2024-08-05 10:03:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire;
|
|
|
|
|
|
2026-02-25 15:38:04 +00:00
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2024-09-05 15:54:32 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2026-02-25 15:38:04 +00:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2024-09-23 17:51:31 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Livewire\Component;
|
2024-08-05 10:03:36 +00:00
|
|
|
|
|
|
|
|
class NavbarDeleteTeam extends Component
|
|
|
|
|
{
|
2026-02-25 15:38:04 +00:00
|
|
|
use AuthorizesRequests;
|
|
|
|
|
|
2024-09-05 15:54:32 +00:00
|
|
|
public $team;
|
|
|
|
|
|
|
|
|
|
public function mount()
|
2024-08-05 10:03:36 +00:00
|
|
|
{
|
2024-09-05 15:54:32 +00:00
|
|
|
$this->team = currentTeam()->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function delete($password)
|
|
|
|
|
{
|
2026-02-25 15:38:04 +00:00
|
|
|
try {
|
|
|
|
|
if (! verifyPasswordConfirmation($password, $this)) {
|
2024-08-05 10:03:36 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-25 15:38:04 +00:00
|
|
|
$currentTeam = currentTeam();
|
|
|
|
|
$this->authorize('delete', $currentTeam);
|
|
|
|
|
|
|
|
|
|
$currentTeam->members->each(function ($user) use ($currentTeam) {
|
|
|
|
|
if ($user->id === Auth::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();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Cache::forget('user:'.Auth::id().':team:'.$currentTeam->id);
|
|
|
|
|
$currentTeam->delete();
|
|
|
|
|
|
|
|
|
|
$newTeam = Auth::user()->teams()->first();
|
|
|
|
|
refreshSession($newTeam);
|
|
|
|
|
|
|
|
|
|
return redirect()->route('team.index');
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
return handleError($e, $this);
|
|
|
|
|
}
|
2024-08-05 10:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.navbar-delete-team');
|
|
|
|
|
}
|
|
|
|
|
}
|