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
is it a users table or something?
from their own docs
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
yup, their docs explain how to do this
please read the screenshot i sent
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