2023-03-24 14:54:17 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
|
|
|
|
|
use App\Models\Team;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class SwitchTeam extends Component
|
|
|
|
{
|
2023-06-02 12:34:45 +02:00
|
|
|
public string $selectedTeamId = 'default';
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-02 12:34:45 +02:00
|
|
|
public function updatedSelectedTeamId()
|
|
|
|
{
|
|
|
|
$this->switch_to($this->selectedTeamId);
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-03-24 14:54:17 +01:00
|
|
|
public function switch_to($team_id)
|
|
|
|
{
|
|
|
|
if (!auth()->user()->teams->contains($team_id)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$team_to_switch_to = Team::find($team_id);
|
|
|
|
if (!$team_to_switch_to) {
|
|
|
|
return;
|
|
|
|
}
|
2023-09-08 18:33:26 +02:00
|
|
|
refreshSession($team_to_switch_to);
|
2023-03-24 14:54:17 +01:00
|
|
|
return redirect(request()->header('Referer'));
|
|
|
|
}
|
|
|
|
}
|