Add a link to the admin panel in user menu

Hi, I have 2 panels, one for customers and one for admins. I want to add a User Menu Item for the Admin panel if the user has access to it. How do I do this? Auth::user() gives me a null in the AdminPanelServiceProvider so I think it is evaluated before the user's session exists?
4 Replies
sumardi
sumardi16mo ago
Try this
$panel
->userMenuItems([
MenuItem::make()
->label('Settings')
->visible(fn () => auth()->user()->is_admin)
->url(route('filament.admin.pages.settings'))
->icon('heroicon-o-cog-6-tooth'),
// ...
]);
$panel
->userMenuItems([
MenuItem::make()
->label('Settings')
->visible(fn () => auth()->user()->is_admin)
->url(route('filament.admin.pages.settings'))
->icon('heroicon-o-cog-6-tooth'),
// ...
]);
FunnyHat
FunnyHatOP16mo ago
There is no visible method on MenuItem I tried this:
MenuItem::make()
->when(fn() => Auth::user()->canAccessPanel(Filament::getPanel('admin')))
->label('Admin')
->color(Color::Red)
->icon('heroicon-o-shield-exclamation')
MenuItem::make()
->when(fn() => Auth::user()->canAccessPanel(Filament::getPanel('admin')))
->label('Admin')
->color(Color::Red)
->icon('heroicon-o-shield-exclamation')
But Auth::user() is null
sumardi
sumardi16mo ago
Argh, wait for this PR to be merge
sumardi
sumardi16mo ago
GitHub
Feature: hide menu item by sumardi · Pull Request #7477 · filamentp...
Changes have been thoroughly tested to not break existing functionality. New functionality has been documented or existing documentation has been updated to reflect changes. Visual changes are ex...
Want results from more Discord servers?
Add your server