Load different data based on the role
Hi guys, My project has 2 roles, "admin" and "contractor". There is a ClientCaseResource and If the logged in user is an admin, I want to list down all the client cases in the table. If the logged in uses is a contractor, I want to list down the client cases which are assigned only to that user. How to achieve this in Filament? TIA!
Solution:Jump to solution
```php
$table
->modifyQueryUsing(
fn (Builder $query) => $query->when(
auth()->user()->hasRole('contractor'),...
4 Replies
You can change the query in the resource https://filamentphp.com/docs/3.x/panels/resources/getting-started#customizing-the-resource-eloquent-query
something like
or something similar
Solution
Thank you very much. This is what I needed.
@Pasindu check this documentation https://filamentphp.com/docs/3.x/panels/tenancy
this is about tenancy but solution with space good enough
better will be to do this mo globally.... especially if you have many records