2023-06-16 13:56:25 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Team;
|
2023-06-16 13:56:25 +00:00
|
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Delete extends Component
|
|
|
|
{
|
|
|
|
public function delete()
|
|
|
|
{
|
2023-08-22 15:44:49 +00:00
|
|
|
$currentTeam = currentTeam();
|
2023-06-16 13:56:25 +00:00
|
|
|
$currentTeam->delete();
|
|
|
|
|
|
|
|
$currentTeam->members->each(function ($user) use ($currentTeam) {
|
|
|
|
if ($user->id === auth()->user()->id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$user->teams()->detach($currentTeam);
|
|
|
|
$session = DB::table('sessions')->where('user_id', $user->id)->first();
|
|
|
|
if ($session) {
|
|
|
|
DB::table('sessions')->where('id', $session->id)->delete();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-08-22 15:44:49 +00:00
|
|
|
refreshSession();
|
2023-08-30 14:01:38 +00:00
|
|
|
return redirect()->route('team.index');
|
2023-06-16 13:56:25 +00:00
|
|
|
}
|
|
|
|
}
|