coolify/app/Livewire/NavbarDeleteTeam.php

48 lines
1.1 KiB
PHP
Raw Normal View History

<?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;
class NavbarDeleteTeam extends Component
{
2024-09-05 15:54:32 +00:00
public $team;
public function mount()
{
2024-09-05 15:54:32 +00:00
$this->team = currentTeam()->name;
}
public function delete($password, $selectedActions = [])
2024-09-05 15:54:32 +00:00
{
if (! verifyPasswordConfirmation($password, $this)) {
return 'The provided password is incorrect.';
2024-09-05 15:54:32 +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()) {
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();
return redirectRoute($this, 'team.index');
}
public function render()
{
return view('livewire.navbar-delete-team');
}
}