How to show panel navigation only to certain users?

i want to show only the navigation to the user with id 1
im trying this:
class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->navigation(auth()->id() === 1)

            // also tried:
            // ->navigation(fn (): bool => auth()->id() === 1)
            // ->navigation((fn (): bool => auth()->id() === 1)())

but
auth()->id()
is always null, despite being logged in or not
Solution
create a middleware:

php artisan make:middleware YourMiddleware


YourMiddleware.php
public function handle(Request $request, Closure $next): Response
{
    $panel = filament()->getCurrentPanel();

    if (auth()->id() !== 1) {
        $panel->navigation(false);
    }

    return $next($request);
}


return $panel
...
    ->authMiddleware([
        Authenticate::class,
        YourMiddleware::class,
    ])
Was this page helpful?