lasthourcloud/app/Http/Livewire/SwitchTeam.php

28 lines
641 B
PHP
Raw Normal View History

<?php
namespace App\Http\Livewire;
use App\Models\Team;
use Livewire\Component;
class SwitchTeam extends Component
{
2023-06-02 10:34:45 +00:00
public string $selectedTeamId = 'default';
public function updatedSelectedTeamId()
{
$this->switch_to($this->selectedTeamId);
}
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;
}
session(['currentTeam' => $team_to_switch_to]);
return redirect(request()->header('Referer'));
}
}