Answer the question
In order to leave comments, you need to log in
How to add roles (Role) separated by commas in a separate field, to the list of users (User) in Laravel 4, using model methods?
//User model
$users = DB::table($this->table)
->join('role_users', 'users.user_id', '=', 'role_users.user_id')
->join('roles', 'role_users.role_id', '=', 'roles.id')
->groupBy(['users.email'])
->select('users.user_id as user_id', 'users.email as email')
->addSelect(DB::Raw("GROUP_CONCAT(roles.name SEPARATOR ', ') as `roles`"))
->paginate(15);
return $users;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question