F
Filament7mo ago
MZX

How do I hide panels based on the User who is logged in? Its for a school management system.

The Admin and teachers would be accessing the panels, and I want the teachers to have a limited access of the system, i.e, some panels will be hidden from them. How do I go about that? I read the docs but couldn't find anything similar expect tenancy but I believe that complicates things and there should be an easier way considering how Filament makes everything easier.
7 Replies
Abi
Abi7mo ago
This has been asked multiple times on this forum, can you search the forum.
Nuekrato
Nuekrato7mo ago
If you use multiple panels just adjust the canAccessPanel-method of your User-model to distinguish between the different panels (you have access to the $panel-variable in that method). According to the docs:
Since you have access to the current $panel, you can write conditional checks for separate panels. For example, only restricting access to the admin panel while allowing all users to access the other panels of your app:
Povilas K
Povilas K7mo ago
@MZX it would be easier to help if you specify the actual example of what do you mean by "some panels will be hidden from them", which panels/resources etc. Because the solution may be pretty individual depending on scenario: restrict panels? use policies? tenancy? etc
MZX
MZXOP7mo ago
Basically, its for a school management app. The admin has access to the entire panel with the options to add different resources. But I would like the teachers to have access to the same panel but with limited options (I don't want them to be able to add/delete/modify some resources, only the admin can) @PovilasKorop Hopefully I was able to articulate it well
Povilas K
Povilas K7mo ago
@MZX so yeah, it means you're working within the same panel, then it's a simple version of just using Laravel Policies as the link stated earlier. Or another example specifically for Deleting records: https://filamentphp.com/docs/3.x/panels/resources/deleting-records#authorization
MZX
MZXOP7mo ago
Alright, thanks a lot, I'll look into it
Want results from more Discord servers?
Add your server