coolify/app/Livewire/SwitchTeam.php

36 lines
737 B
PHP
Raw Normal View History

<?php
2023-12-07 19:06:32 +01:00
namespace App\Livewire;
use App\Models\Team;
use Livewire\Component;
class SwitchTeam extends Component
{
2023-06-02 12:34:45 +02:00
public string $selectedTeamId = 'default';
2024-06-10 22:43:34 +02:00
public function mount()
{
2024-03-21 14:30:35 +01:00
$this->selectedTeamId = auth()->user()->currentTeam()->id;
}
2024-06-10 22:43:34 +02:00
2023-06-02 12:34:45 +02:00
public function updatedSelectedTeamId()
{
$this->switch_to($this->selectedTeamId);
}
public function switch_to($team_id)
{
2024-06-10 22:43:34 +02:00
if (! auth()->user()->teams->contains($team_id)) {
return;
}
$team_to_switch_to = Team::find($team_id);
2024-06-10 22:43:34 +02:00
if (! $team_to_switch_to) {
return;
}
2023-09-08 18:33:26 +02:00
refreshSession($team_to_switch_to);
2024-06-10 22:43:34 +02:00
return redirect(request()->header('Referer'));
}
}