Level 75
@martin20 I redid my final answer here https://laracasts.com/discuss/channels/laravel/i-want-to-display-all-roles-who-this-user-id-dont-have
And it works.
Eloquent results are arrayable but query builder is not directly arrayable.
2 likes
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
here is table structure i know ec_users and user_id is wrong but i don't have permission to change -
ec_users
- user_id
- name
- email
roles
- id
- name
model_has_roles
- role_id
- model_type
- model_id
i know is something like that but i don't know how to add relationship
$userId = 1;
$roles = Role::whereDoesntHave('users', function ($query) use ($userId) {
$query->where('users.id', $userId);
})->get();
@martin20 I redid my final answer here https://laracasts.com/discuss/channels/laravel/i-want-to-display-all-roles-who-this-user-id-dont-have
And it works.
Eloquent results are arrayable but query builder is not directly arrayable.
Please or to participate in this conversation.