Really without seeing all code you used, it's probably a matter of tweaking your authorization whether it be a gate or policy.
Sep 25, 2024
2
Level 6
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
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.