29 lines
697 B
PHP
29 lines
697 B
PHP
|
<?php declare(strict_types=1);
|
||
|
|
||
|
namespace App\Repository;
|
||
|
|
||
|
use App\Entity\Brand;
|
||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||
|
use Doctrine\ORM\Query;
|
||
|
use Doctrine\Persistence\ManagerRegistry;
|
||
|
|
||
|
class BrandRepository extends ServiceEntityRepository {
|
||
|
public function __construct(ManagerRegistry $registry)
|
||
|
{
|
||
|
parent::__construct($registry, Brand::class);
|
||
|
}
|
||
|
|
||
|
public function filterByCategory(string $category): Query
|
||
|
{
|
||
|
$em = $this->getEntityManager();
|
||
|
$query = $em->createQuery("
|
||
|
SELECT b FROM App\Entity\Brand b
|
||
|
INNER JOIN b.categories c WHERE c.name = ?1
|
||
|
ORDER BY b.name ASC
|
||
|
");
|
||
|
$query->setParameter(1, $category);
|
||
|
|
||
|
return $query->execute();
|
||
|
}
|
||
|
}
|