I need to get all the user from my database excluding only the user that belongs to Admin
and Staff
group and I need, for each of them, to get their profile so I used the Eager Loading:
$data['users'] = User::with('profile')->join('role_user', function($join){
$join->on('role_user.user_id', '=' , 'users.id');
})
->join('roles', function($join){
$join->on('roles.id', '=', 'role_user.role_id');
})
->whereNotIn('roles.name', ['Admin', 'Staff'])
->withTrashed()
->paginate(10);
My DB Table:
users:
id | email | password
profile:
user_id | first_name | last_name
roles:
id | name
role_user:
user_id | role_id |
The problem is that the code above works with user
infos but shows only the first profile
so I have the same first_name and last_name
with different email