Skip to content

Filters

APIPlatform allows you to filter collections of resources. Filters are automatically enabled for all properties of the resource.

A filter can be configured either per entity or per property. Filters are configured in the ApiFilter attribute. It is possible to use multiple filters for a single entity or property.

Examples of common filters are:

  • SearchFilter: Allows you to search for resources based on a set of properties.
  • OrderFilter: Allows you to order resources based on a set of properties.
  • DateFilter: Allows you to filter resources based on a date range.
  • BooleanFilter: Allows you to filter resources based on boolean values.
#[ApiFilter(SearchFilter::class,
    properties: [
        'id'                => 'exact',
        'display_name'      => 'partial',
        'email'             => 'partial'
    ]
)]
#[ApiFilter(SearchFilter::class,
    properties: [
        'roles'             => 'partial'
    ]
)]
class User
{
    // ...
}

Each property can have a different filter. In the example above, the id property uses the exact filter, while the display_name and email properties use the partial filter. Case-insensitive filters are also available:

iexact, ipartial, icontains, iendswith, istartswith.

Consult the API Platform documentation for filters for more information on filters.