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-12-07 21:56:55 +00:00
|
|
|
return $this->redirectRoute('team.index', navigate: true);
|
2023-06-16 13:56:25 +00:00
|
|
|
}
|
|
|
|
}
|