How to filter many to many structure in Laravel How to filter many to many structure in Laravel php php

How to filter many to many structure in Laravel


This should give you all users who are admins.

$users = User::whereHas('roles', function($q) {    $q->where('name', '=', 'admins');})->get();

You can see more information on the has() method at http://laravel.com/docs/eloquent#querying-relations