Is there a way to conditionally hide the Tenant Registration Link in the Tenant Menu?
Do you know if it is possible to hide the Tenant Registration Link in the Tenant Menu conditionally?
E.g. Check if User has the Right to Create Tenants
24 Replies
In the registration tenant page class, override the parent
mount()
method.
I just did this recently
Oh I'm sorry, I was misread your issue.Yes but I think it is kind of a workaround but ideally i will also hide the Tenant Registration Link in the Tenant Menu.
I'm looking for a solution for this as well. So far, I haven't found a way to conditionally show/hide the link. @benny.dev 's workaround is a nice one.
I think I may have found a way. It's not pretty but it works. Basically, create a new file in
resources\views\vendor\filament-panels\components\
called tenant-menu.blade.php
. To preserve all the functionality as-is, copy the contents of vendor\filament\filament\resources\views\components\tenant-menu.blade.php
and paste it in the new file you just created. Then add your checks in the @php section. In my case, I wanted to hide the menu for all users except admins. This is what I did
â ď¸ Warning â ď¸
I assume this may introduce breaking changes into your application in future updates. Use at your own discretion.
@Dan Harrin may be able to corroborate this. Thoughts?if the user doesn't have permission to create a tenant in the Policy, the link shouldnt show
Oh
I'm going to try that. Thank you!
it should also throw a 403
Whats the name of policy function for this?
My teant model is Clinic. So I created a ClinicPolicy with
php artisan make:policy ClinicPolicy
. Just to be safe, I registered the new policy manually in AuthServiceProvider
Then, I added the following policy method
But the menu item still shows up. Did I not do this correctly?It didn't throw a 403 either
I've already deleted the /resources/views/vendor folder and cleared browser cache.
which v3 patch version are you on?
please make sure you also delete any published views
In the tenant-menu.blade.php I can see how the profile page is observing tenant policies, not the case for the registration page
Is this pull request worthy?
Oh, I just noticed the RegisterTenant page class doesn't have a canView() method
the base class should, right?
you mean the abstract RegisterTenant class?
if so, then no. The base
RegisterTenant
class does not have a ::canView()
methodit does though...
please make sure you're on the latest version
makes sense * hides in shame *
so it works correctly on the latest version, right?
I'm testing that now. I did
php artisan filament:upgrade
but I can't see the canView method still. Trying to figure out if I'm missing somethingcomposer update?
read my mind
doing that now
That did the trick! Menu item is gone! Woohoo!
I gotta make a video about this one đ¤