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

31 lines
827 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()
{
$currentTeam = session('currentTeam');
$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();
}
});
session(['currentTeam' => $team]);
return redirect()->route('team.show');
}
}