Route Configuration
To enable filtering for a specific route, you use thefiltering() method on the Route object. This automatically handles the documentation and request parameter resolution.
Type-Safe Filtering
Apivalk provides specialized filter classes for different property types. This ensures that the filter values are correctly type-casted when retrieved in your controller.- StringFilter: Linked to
StringProperty. Supportsequals,in,like, andcontains. - NumberFilter: Linked to
NumberProperty. Supportsequals,in,greaterThan, andlessThan. - DateFilter: Linked to
StringPropertywithdateformat. Returns\DateTimevalues. - DateTimeFilter: Linked to
StringPropertywithdate-timeformat. Returns\DateTimevalues.
- OpenAPI Accuracy: The documentation reflects the correct data type (e.g.,
number,integer,string). - Automatic Casting:
getValue()returns the correct PHP type (string,int, orfloat). - Detailed Documentation: You can add custom descriptions, examples, and constraints to your filters.
Supported Filter Types
StringFilter
StringFilter::equals(StringProperty $property): Exact match for a single string.StringFilter::in(StringProperty $property): Match against a list of strings.StringFilter::like(StringProperty $property): Partial string matching (e.g.,prefix%).StringFilter::contains(StringProperty $property): Match if a string contains another.
NumberFilter
NumberFilter::equals(NumberProperty $property): Exact numeric match.NumberFilter::in(NumberProperty $property): Match against a list of numbers.NumberFilter::greaterThan(NumberProperty $property): Numeric comparison.NumberFilter::lessThan(NumberProperty $property): Numeric comparison.
DateFilter
DateFilter::equals(StringProperty $property): Exact date match.DateFilter::in(StringProperty $property): Match against a list of dates.DateFilter::greaterThan(StringProperty $property): Date comparison.DateFilter::lessThan(StringProperty $property): Date comparison.
DateTimeFilter
DateTimeFilter::equals(StringProperty $property): Exact date-time match.DateTimeFilter::in(StringProperty $property): Match against a list of date-times.DateTimeFilter::greaterThan(StringProperty $property): Date-time comparison.DateTimeFilter::lessThan(StringProperty $property): Date-time comparison.
Usage in Controller
When a route has filtering enabled, you can access the resolved filters from the request via thefiltering() method.
Client-Side Usage
Apivalk supports filtering using flat key-value parameters in the query string. This is ideal for simple, direct matching. Example: retrieve all active contractsGET /contracts?status=active
OpenAPI Documentation
When you configure filters on a route, Apivalk automatically generates the corresponding OpenAPI documentation:- Individual query parameters for each filter.
- Descriptions including the supported match type (e.g.,
equals,in). - Type information based on the configured properties (e.g.,
integer,string,number).