Skip to content

Instantly share code, notes, and snippets.

View silverbackdan's full-sized avatar

Daniel West silverbackdan

View GitHub Profile
@silverbackdan
silverbackdan / OrSearchFilter.php
Last active July 12, 2023 09:30
The API Platform filter will allow you to pass a query `or[field1,field2]=value` to search multiple fields for a search value. It works by using the standard API Platform SearchFilter as a basis, and wrapping all of your OR queried inside a single AND query so you can combine with other where bys
<?php
declare(strict_types=1);
namespace App\Filter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use App\Entity\Term;