Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anonymouse703's avatar

How to hide Dashboard on Menu depends on user role?

I already set policy and was able to hide menus depend on the user's role... However one of my role should have access for two modules only the series and playlist but the problem is the Dashboard is still accessible. I want to hide the Dashboard also for that specific role

0 likes
2 replies
jlrdw's avatar

Really without seeing all code you used, it's probably a matter of tweaking your authorization whether it be a gate or policy.

anonymouse703's avatar
anonymouse703
OP
Best Answer
Level 6

@jlrdw I already implement the policy on all models only on the Dashboard navigation item.. but I already solve by adding canAccess function and add login response to redirect user to it's specific default url

on my Dashboard.php I add this

 public static function canAccess(): bool
    {
        if(auth()->user()->role === Role::Translator){
            return false;
        }

        return true;
    }

then in LoginResponse

<?php

namespace App\Http\Responses;

use App\Enums\User\Role;
use Illuminate\Http\RedirectResponse;
use App\Filament\Resources\SeriesResource;
use Livewire\Features\SupportRedirects\Redirector;

class LoginResponse extends \Filament\Http\Responses\Auth\LoginResponse
{
    public function toResponse($request): RedirectResponse|Redirector
    {
        if(auth()->user()->role === Role::Translator){
            return redirect()->to(SeriesResource::getUrl('index'));
        }else{
            return redirect()->to('admin');
        }
    }
}

Just register the LoginResponse in the AppServiceProvider

    public function register(): void
    {
   
        $this->app->singleton(
            LoginResponse::class,
            \App\Http\Responses\LoginResponse::class
        );
    }

Please or to participate in this conversation.