mardi 31 mai 2016

Laravel order user by role

I have table users and pivot table role_user, not every user has a role. I need to make a query and get all users, and order them by roles, which join statement should I use then, how would that query look like then? I need some similar query to this, but so that users with that have roles come first and not the ones that don't have roles like now:

$users = DB::table('users')
                     ->leftJoin('role_user', 'users.id', '=', 'role_user.user_id')
                     ->orderBy('role_id')
                     ->get();



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1TUKRwP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire