0

I have 2 tables

Users :  
id
name
Roles :
id
name

These two tables have a many to many relationship with the pivot table

Role_user : 
role_id
user_id

How do I group all users by role name? I tried this but it seems to work only for one to many relationships

User::with('roles')->get()->groupBy('roles.name');

Something like that

0 Answers0