Fetching users with role admin within a LookupTableBuilder
Created 3 years ago by william

I have a LookupTableBuilder where i want to fetch only users with the role admin. How do we do that? Tried the below but i guess that's not the way.

$query->with(['roles'=> function ($q) {
        $q->where('slug', 'admin');
william  —  3 years ago Best Answer

This is the way

$query->whereHas('roles', function ($q) {
        $q->whereIn('slug', ['admin']);
ryanthompson  —  3 years ago

@william nicely done! I can't say I've ever done that before but looks like it runs off the existing relationship? Very nice.