2024-08-05 10:03:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire;
|
|
|
|
|
|
2024-09-05 15:54:32 +00:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
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
|
|
|
|
|
{
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 14:04:45 +00:00
|
|
|
public function delete($password, $selectedActions = [])
|
2024-09-05 15:54:32 +00:00
|
|
|
{
|
2025-12-12 13:12:02 +00:00
|
|
|
if (! verifyPasswordConfirmation($password, $this)) {
|
2026-03-11 14:04:45 +00:00
|
|
|
return 'The provided password is incorrect.';
|
2024-09-05 15:54:32 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-05 10:03:36 +00:00
|
|
|
$currentTeam = currentTeam();
|
|
|
|
|
$currentTeam->delete();
|
|
|
|
|
|
|
|
|
|
$currentTeam->members->each(function ($user) use ($currentTeam) {
|
2024-11-22 17:14:47 +00:00
|
|
|
if ($user->id === Auth::id()) {
|
2024-08-05 10:03:36 +00:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
refreshSession();
|
|
|
|
|
|
2025-12-26 12:29:53 +00:00
|
|
|
return redirectRoute($this, 'team.index');
|
2024-08-05 10:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.navbar-delete-team');
|
|
|
|
|
}
|
|
|
|
|
}
|