Overview
Rest Generic Class provides a flexible dynamic filtering system that allows clients to build complex queries using theoper parameter. The system supports:
- Multiple comparison operators (equality, range, pattern matching)
- Logical grouping with
and/orconditions - Nested filter structures for advanced queries
- Automatic table prefixing to avoid column ambiguity
- Database-specific features (PostgreSQL
ilike, unaccent)
Basic Filter Structure
Filters are passed via theoper query parameter as a JSON object with logical operators:
field|operator|value
Supported Operators
The filtering system supports a comprehensive set of operators:Comparison Operators
Pattern Matching
List Operators
Range Operators
Null Operators
Date Operators
Existence Operators
Logical Operators
AND Conditions
All conditions must be true:OR Conditions
At least one condition must be true:Nested Conditions
Combine AND/OR logic for complex queries:Value Types
The filter system automatically decodes values:Configuration
Configure filtering behavior inconfig/rest-generic-class.php:
HasDynamicFilter Trait
The filtering logic is implemented in theHasDynamicFilter trait, which provides:
scopeWithFilters
Apply filters to an Eloquent query:Key Methods
Advanced Examples
Search with Multiple Conditions
Complex Business Logic
Find active products that are either featured OR low in stock:Pattern Matching Search
Date Range Filtering
Security Considerations
Performance Tips
- Index filtered columns: Add database indexes to commonly filtered fields
- Limit nesting depth: Keep filter structures simple when possible
- Use specific operators:
=is faster thanlike - Avoid leading wildcards:
name|like|%termis slower thanname|like|term% - Enable column caching: Reduces validation overhead
Error Handling
Common filtering errors:Related Documentation
- Relation Loading - Filter on related models
- HasDynamicFilter Trait - Trait API reference
- Advanced Filtering Guide - Detailed examples
- Configuration - Filtering configuration options