F
Filamentβ€’11mo ago
Rah Dean

Setting the default tenant doesn't seem to work as expected

I'm running Filament v3.2.2 and I followed the docs in setting the default tenant https://filamentphp.com/docs/3.x/panels/tenancy#setting-the-default-tenant However, Filament doesn't seem to update the 'latest_team_id' field of the users table in the database whenever I change the tenant using the tenant menu. Is this the expected behavior? If so, how do I hook into the tenant menu to update the 'latest_team_id' field when changing tenant? I tried manually updating the 'latest_team_id' field in the database and Filament picks it up and redirects me to the correct team's dashboard whenever I sign in.
3 Replies
Thijmen
Thijmenβ€’11mo ago
Bump
Sjoerd24
Sjoerd24β€’11mo ago
I think filament doesn't do this automatically, so I did it myself. Made a function in User model:
public function setCurrentClinic(int $clinic_id): void
{
$this->current_clinic_id = $clinic_id;
$this->save();
}
public function setCurrentClinic(int $clinic_id): void
{
$this->current_clinic_id = $clinic_id;
$this->save();
}
And in a middleware that I'm using to check some rights (using spatie permissions/teams)
$filament = Filament::getTenant()->id;
auth()->user()->setCurrentClinic($filament);
$filament = Filament::getTenant()->id;
auth()->user()->setCurrentClinic($filament);
Now it all works perfectly with me. Although it is probably not the most elegant solution. πŸ™‚
Rah Dean
Rah DeanOPβ€’11mo ago
Thank you
Want results from more Discord servers?
Add your server