You can not use auth()->user()
in AppServiceProvider::class
.
php artisan make:middleware UserMenuItemMiddleware
config/filament.php
)'middleware' => [ 'auth' => [ Authenticate::class, UserMenuMiddleware::class, // <here ], 'base' => [ EncryptCookies::class, AddQueuedCookiesToResponse::class, StartSession::class, AuthenticateSession::class, ShareErrorsFromSession::class, VerifyCsrfToken::class, SubstituteBindings::class, DispatchServingFilamentEvent::class, MirrorConfigToSubpackages::class, InitializeTenancyBySubdomain::class, PreventAccessFromCentralDomains::class, ],],
UserMenuItemMiddleware
public function handle(Request $request, Closure $next){ if (auth()->user()->hasRole("super_admin")) { Filament::registerUserMenuItems([ 'link' => UserMenuItem::make()->label('Custom Label')->url("Your Link") ]); } Filament::registerUserMenuItems([ 'account' => UserMenuItem::make()->label('My Profile')->url('/admin/my-profile') ]); return $next($request);}
That its now you can have conditions on your custom user menu items.
No comments yet…