How do I filter data by permission

I have a table of Orders. So i have OrderResource but how do i filter the order based on type. For example, my roles wheelchair should only be able to see the Order type wheelchair while admin is able to see everything Thanks in advance :(
8 Replies
krekas
krekas3mo ago
you should modify the query based on the users role
BakaPresident
BakaPresident3mo ago
Using the table function right? Does Policy work the same? I think i poked around it seems filament reflects it on the policy too
krekas
krekas3mo ago
policies restrict access to the page. to need to modify query https://discord.com/channels/883083792112300104/1229129156361588958 could use search for similar topics
BakaPresident
BakaPresident3mo ago
ahh okay thanks! Sorry quick question. I have the following code now
->modifyQueryUsing(function (Builder $query) {
if (Auth::user()->hasRole(['general-admin'])) {
return $query;
} else if (Auth::user()->hasRole(['wheelchair-admin'])) {
return $query->where('bus_type', BusOrderType::Wheelchair);
} else {
return null;
}
})
->modifyQueryUsing(function (Builder $query) {
if (Auth::user()->hasRole(['general-admin'])) {
return $query;
} else if (Auth::user()->hasRole(['wheelchair-admin'])) {
return $query->where('bus_type', BusOrderType::Wheelchair);
} else {
return null;
}
})
I tried debugging it. It seems to know to go to the return null portion but for some reason it still returns the entire table (i.e return $query)
krekas
krekas3mo ago
Because you only modify the portion of the query
BakaPresident
BakaPresident3mo ago
okay so must i do like $query = null then return $query;?
krekas
krekas3mo ago
No. You need to modify the whole query. But I don't think it can be null
BakaPresident
BakaPresident3mo ago
Ahh okay... It's okay i'll just return a query that always return false
Want results from more Discord servers?
Add your server
More Posts