public function scopeWithRole($query, $role)
    {
        return $query->whereHas('roles', function ($query) use ($role)
        {
            $query->where('name', $role);
        });
    }
public function scopeWithRole($query, $role)
    {
        return $query->whereHas('roles', function ($query) use ($role)
        {
            $query->where('name', $role);
        });
    }
public function scopeWithRole ( $ query , $ role ) { return $ query -> whereHas ( 'roles' , function ( $ query ) use ( $ role ) { $ query -> where ( 'name' , $ role ) ; } ) ; }
Filtering users according to their role

@param string $role
@return users collection
Filtering users according to their role