Eloquent Builder with relationships

I could use $user->hasRole('admin') to identify admins. But filament uses query builder for generating tables: parent::getEloquentQuery(). How do I make it so that parent::getEloquentQuery would generate table with only admin records? ->with('roles') isn't working. (I am using spatie permissions)
5 Replies
Dan Harrin
Dan Harrin2y ago
is it a users table or something?
Dan Harrin
Dan Harrin2y ago
from their own docs
Positiverain
PositiverainOP2y ago
yeh it is a users table, which is some how linked to roles table.. I am talking about this function from the user resource public static function getEloquentQuery(): Builder {....} which builds the table, Usually there is return parent::getEloquentQuery(); But I want only admins to be shown on the table
Dan Harrin
Dan Harrin2y ago
yup, their docs explain how to do this please read the screenshot i sent
Positiverain
PositiverainOP2y ago
yeh it does work with finding only admins, but what if i want multiple roles? return User::role('admin'); works, but i also want to show the users along with admin return User::role(['admin','user']); doesn't work Nvm I used parent::getEloquentQuery()->whereHas('roles', function($q) { return $q after where} and it fixed the problem
Want results from more Discord servers?
Add your server