public function scopeHavingRoles($query, array $roles)
    {
        return $query->whereExists(function ($query) use ($roles) {
            $query->selectRaw('1')
                  ->from('role_user')
                  ->whereRaw('role_user.user_id = users.id')
                  ->whereIn('role_id', $roles);
        });
    }
public function scopeHavingRoles($query, array $roles)
    {
        return $query->whereExists(function ($query) use ($roles) {
            $query->selectRaw('1')
                  ->from('role_user')
                  ->whereRaw('role_user.user_id = users.id')
                  ->whereIn('role_id', $roles);
        });
    }
public function scopeHavingRoles ( $ query , array $ roles ) { return $ query -> whereExists ( function ( $ query ) use ( $ roles ) { $ query -> selectRaw ( '1' ) -> from ( 'role_user' ) -> whereRaw ( 'role_user.user_id = users.id' ) -> whereIn ( 'role_id' , $ roles ) ; } ) ; }
Query scope for user having the given roles.

@param \Illuminate\Database\Eloquent\Builder $query
@param array $roles
@return mixed
Query scope for user having the given roles .