collection-crud/src/Form/BrandCategoryTrait.php

19 lines
422 B
PHP

<?php declare(strict_types=1);
namespace App\Form;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
trait BrandCategoryTrait {
public static function filterBrands(string $filter): callable
{
return static fn(EntityRepository $e) =>
$e->createQueryBuilder('b')
->join('b.categories', 'bc')
->where('bc.name=:name')
->orderBy('b.name', 'ASC')
->setParameter('name', $filter);
}
}