public function getUsersForRole($role, $withAdmin = false)
    {
        $query = $this->userModel->query()
            ->orderBy('email')
            ->whereHas('roles', function ($query) use ($role) {
                $query->where('slug', $role);
            });

        if ( ! $withAdmin) {
            $query->where('is_superadmin', false);
        }

        return $query->get();
    }
public function getUsersForRole($role, $withAdmin = false)
    {
        $query = $this->userModel->query()
            ->orderBy('email')
            ->whereHas('roles', function ($query) use ($role) {
                $query->where('slug', $role);
            });

        if ( ! $withAdmin) {
            $query->where('is_superadmin', false);
        }

        return $query->get();
    }
public function getUsersForRole ( $ role , $ withAdmin = false ) { $ query = $ this -> userModel -> query ( ) -> orderBy ( 'email' ) -> whereHas ( 'roles' , function ( $ query ) use ( $ role ) { $ query -> where ( 'slug' , $ role ) ; } ) ; if ( ! $ withAdmin ) { $ query -> where ( 'is_superadmin' , false ) ; } return $ query -> get ( ) ; }
Returns all CMS users with the given role.

@param string $role
@param bool   $withAdmin include superadmins
@return array|Collection|UserInterface[]
Returns all CMS users with the given role .