Eager-loading using with results in a separate query. You User object(s) will have a role property; you can get the role name through that:
$user->role->name;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi . I want to get builder with eloquent builder not using join.
return User::query()
->join('roles', 'users.role_id', '=', 'roles.id')
->select('users.*', 'roles.name as role');
it works.
But I want to use simple way using 'with' .
return User::query()
->with('role')
->select('users.*', 'roles.name as role');
But it shows error.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'roles.name' in 'field list'
roles table has 'name' field.
How can I do this ?
@binggle eager-loading is supported. So, is the problem that two columns have the same header row; it appears that you can modify that https://livewire-powergrid.com/#/table/include-columns?id=column-methods
Please or to participate in this conversation.