Skip to content

Instantly share code, notes, and snippets.

@platoosom
Created September 28, 2017 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save platoosom/333a595e101bf5433c6804b9fe852e25 to your computer and use it in GitHub Desktop.
Save platoosom/333a595e101bf5433c6804b9fe852e25 to your computer and use it in GitHub Desktop.
$query = User::select([ 'users.*', DB::raw('count(roles.id) as roles_count') ])
->join('user_roles', 'users.id', '=', 'roles.user_id')
->groupBy('users.id')
->having('roles_count', '>', 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment