Eager loading roles with admin users
Hi,
I am running this query
$institutionsList = Institution::select('id', 'name')->where('someid', '=', $someid)->with('admins:first_name,last_name,admins.uuid')->orderBy('name')->get();
It returns a list of institutions with the related admins
As I am using Spatie/permissions, I would also like to get the roles, How can I do that?
You can eager-load nested relations using dot-syntax, so, if the Admin class has a roles relation it would be admins.roles like so:
$institutionsList = Institution::select('id', 'name')
->where('someid', '=', $someid)
->with('admins:first_name,last_name,admins.uuid, admins.roles')
->orderBy('name')
->get();
Great. thank you!
the solution was
->with('admins:first_name,last_name,admins.uuid','admins.roles')
whoops, I meant
->with('admins:first_name,last_name,uuid')->with('admins.roles:name')
Please or to participate in this conversation.