how would I add a user menu item dynamically?

I have added the example in a custom provider and it works. Now I want to apply this for only some users
Filament::serving(function () {
if (auth()->user->can('access tools')) {
Filament::registerUserMenuItems([
UserMenuItem::make()
->label('Tools')
->url(route('filament.pages.tools'))
->icon('heroicon-s-cog'),
// ...
]);
});
Filament::serving(function () {
if (auth()->user->can('access tools')) {
Filament::registerUserMenuItems([
UserMenuItem::make()
->label('Tools')
->url(route('filament.pages.tools'))
->icon('heroicon-s-cog'),
// ...
]);
});
} }); I tried auth()->user->can('access tools'); but user is null at this point. user->can('access tools') is a permission (spatie ) that is registered.
2 Replies
Patrick Boivin
Where did you do the check for auth()->user()? I think it should work inside of Filament::serving( ... )
ddoddsr
ddoddsrOP2y ago
Updated the code above to show where I tested for User. and got this message Undefined property: Illuminate\Auth\AuthManager::$user I use the wrong facade use Illuminate\Support\Facades\Auth; S/B if (Auth::user()->can('access tools')) { I'm learning thanks for the question got me to look at it differently
Want results from more Discord servers?
Add your server