Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Argument 1 passed to App\Repository\FooRepository::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry

After updating to doctrine/doctrine-bundle 2.1.2 I'm getting this error:

Argument 1 passed to App\Repository\FooRepository::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry, instance of Doctrine\Bundle\DoctrineBundle\Registry given, called in ...

My Repository looks like this:

namespace App\Repository;

use App\Entity\Foo;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;

class FooRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Foo::class);
    }
}

=> See my own answer below.

like image 696
Thomas Landauer Avatar asked Sep 01 '20 13:09

Thomas Landauer


1 Answers

Just change this use line from

use Doctrine\Common\Persistence\ManagerRegistry;

to

use Doctrine\Persistence\ManagerRegistry;

Documentation: https://symfony.com/doc/current/doctrine.html#querying-for-objects-the-repository

like image 122
Thomas Landauer Avatar answered Nov 14 '22 08:11

Thomas Landauer