I have checked many solutions to get specific columns from first model with eager loading but nothing works in my case.
for example: I want specific columns from model User and want to get relationship data with eager loading without any join.
$users= User::select('name') // get one column from user table
->with(array('role_user' => function($query){
$query->select('role_name'); // and select one column from pivot table
}))
->paginate(3);
when I don't use User::select('name), it returns relationship data with eager load when I use select, it returns empty array.
How I can get specific columns from both tables using eager loading