2024-08-05 10:03:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Livewire;
|
|
|
|
|
|
2024-10-22 10:29:48 +00:00
|
|
|
use App\Models\InstanceSettings;
|
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;
|
2024-09-05 15:54:32 +00:00
|
|
|
use Illuminate\Support\Facades\Hash;
|
2024-09-23 17:51:31 +00:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function delete($password)
|
|
|
|
|
{
|
2024-10-24 14:20:01 +00:00
|
|
|
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
|
2024-10-22 10:29:48 +00:00
|
|
|
if (! Hash::check($password, Auth::user()->password)) {
|
|
|
|
|
$this->addError('password', 'The provided password is incorrect.');
|
2024-09-23 17:51:31 +00:00
|
|
|
|
2024-10-22 10:29:48 +00:00
|
|
|
return;
|
|
|
|
|
}
|
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();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('team.index');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render()
|
|
|
|
|
{
|
|
|
|
|
return view('livewire.navbar-delete-team');
|
|
|
|
|
}
|
|
|
|
|
}
|