public function getUsersWithRole(Role $role): array
    {
        $query = $this->getRepository()->createQueryBuilder('u')
            ->select('u')
            ->where(':role MEMBER OF u.roles')
            ->setParameter('role', $role)
            ->getQuery();

        return $query->getResult() ?? [];
    }
public function getUsersWithRole(Role $role): array
    {
        $query = $this->getRepository()->createQueryBuilder('u')
            ->select('u')
            ->where(':role MEMBER OF u.roles')
            ->setParameter('role', $role)
            ->getQuery();

        return $query->getResult() ?? [];
    }
public function getUsersWithRole ( Role $ role ) : array { $ query = $ this -> getRepository ( ) -> createQueryBuilder ( 'u' ) -> select ( 'u' ) -> where ( ':role MEMBER OF u.roles' ) -> setParameter ( 'role' , $ role ) -> getQuery ( ) ; return $ query -> getResult ( ) ?? [ ] ; }
Get users with a specific role, and _not_ its hierarchical parents.
In other words, if you have 'admin' which inherits from 'standard' and you request 'admin',
you will not list 'standard' users.

@param Role $role

@return array
Get users with a specific role and _not_ its hierarchical parents . In other words if you have admin which inherits from standard and you request admin you will not list standard users .