lasthourcloud/app/Http/Livewire/Team/Delete.php

31 lines
802 B
PHP
Raw Normal View History

2023-06-16 13:56:25 +00:00
<?php
namespace App\Http\Livewire\Team;
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();
$team = auth()->user()->teams()->first();
$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
}
}