Navigation for multi role panel
Hello, I have 2 role super admin and admin on the panel basically it shares a same panel . I need to hide some navigation if he is appear as admin but if he is super admin he can access all navigation and navigate to there, I only want to hide the Admin group section nav and the Other group section. Is there a way to achieve that?

9 Replies
I think for resources a policy should be enough.
And for non resources, you could do the following:
I already tried like that that way but its resulting the navigation items still can be show by admin though
If they're regular resources, make sure your policy is correct. maybe the role query isn't ok?
you mean this one?
<?php
namespace App\Policies;
use App\Models\Brand;
use App\Models\User;
class BrandPolicy
{
/**
* Create a new policy instance.
*/
public function __construct()
{
//
}
public function manageOwn(User $user, Brand $brand)
{
return $user->hasRole('super-admin') || $user->id === $brand->user_id; // Superadmin or owner can manage
}
}
See here how it's handled in Filament resources:
https://filamentphp.com/docs/3.x/panels/resources/getting-started#authorization
in your case it's the
viewAny()
methodtry to override the
shouldRegisterNavigation
resource method:
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
thankyou, the navigation can be hidden now