Ever needed to get the default tenant for a user in your multi-tenant Filament app? I know I did and as (almost) always Filament got a solution ready for you.
In my case currentTeam
and allTeams()
both come from Laravel Jetstream. When I started building the app, it used Livewire 3 and Laravel Jetstream for the multi-tenancy. If you have a similar concept and somehow store the current tenant for the user, you can quickly adjust the code to your liking.
Implement the HasDefaultTenant interface on the User model
Filament provides a HasDefaultTenant
interface that you can simply implement on your User model, in my case like this 👇
Why is this useful?
Normally when you sign into your Filament panel the user will be redirected to the first tenant that is returned from the getTenants()
method. This might be good for some use cases, but in most cases it makes more sense to go back to the last tenant the user was in.
Learn more in the Filament docs
The documentation for Filament is getting better with every release. In the case of getDefaultTenant
, they do have even more on the topic. Go check it out: