Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Martin20's avatar

getting all roles who specific user {id} don't have

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();
0 likes
2 replies
tisuchi's avatar

@martin20 I am not sure what kind of relationship you want to add, can you make it a bit more clear?

1 like

Please or to participate in this conversation.