problem to fetch Json from database with Doctrine

  doctrine, mysql, php, sql, symfony

I use symfony 5 and create a "user" table in my database and my "user" table has "roles" column.

"roles" column is json.

I use this in my Controller for find all user that have "roles" = ["ROLE_USER"] :

public function usersList(EntityManagerInterface $em): Response
{
    $lists = $em->createQueryBuilder()
        ->select('user')
        ->where('user.roles = ["ROLE_USER"]')
        ->getQuery()
        ->execute();

    return $this->render('list.html.twig',[
        'lists' => $lists
    ]);
}

But show me this error:

[Syntax Error] line 0, col 12: Error: Expected
DoctrineORMQueryLexer::T_FROM, got ‘WHERE’

How can I fix this problem?

Source: Ask PHP

LEAVE A COMMENT