Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Query Filters Laravel Package

cerbero/query-filters

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Eloquent-Centric: The package is tightly coupled with Laravel Eloquent, making it ideal for applications where API endpoints or admin panels require dynamic filtering of database records via query parameters (e.g., /posts?status=published&category=tech).
  • Separation of Concerns: Encourages clean separation between route logic and query construction by generating dedicated filter classes (e.g., PostFilter). This aligns with Laravel’s service-layer patterns and reduces route/controller bloat.
  • API/SPA-Friendly: Particularly valuable for RESTful APIs or GraphQL backends where client-driven filtering is common (e.g., pagination, search, or multi-criteria filtering).
  • Limitation: Not suitable for non-Eloquent queries (e.g., raw SQL, query builder without models) or applications avoiding Laravel’s ORM.

Integration Feasibility

  • Low Friction: Composer install + optional service provider registration (for Laravel <5.5) is straightforward. No database migrations or complex setup required.
  • Generator Tool: Built-in php artisan make:query-filter reduces boilerplate for defining filters (e.g., rules for status, date_range, etc.).
  • Configurable: Supports custom filter class paths via config/query_filters.php, allowing alignment with project conventions (e.g., app/Filters).
  • Octane Compatibility: Explicitly supports Laravel Octane, ensuring performance parity in high-concurrency environments.

Technical Risk

  • Validation Overlap: May introduce redundancy if the application already uses Laravel’s built-in validation (e.g., Form Requests). Risk mitigated by designing filters to delegate to existing validation logic.
  • Complex Filter Logic: Poorly structured filter rules (e.g., nested conditions, custom callbacks) could lead to unmaintainable query classes. Mitigate with:
    • Unit tests for filter classes.
    • Clear documentation of rule priorities (e.g., where vs. orWhere).
  • Performance: Deeply nested or poorly optimized filters (e.g., LIKE on large text fields) could degrade query performance. Monitor with Laravel Debugbar or query logging.
  • Dependency Bloat: Adds ~1MB to vendor space (minimal impact for most projects).

Key Questions

  1. Use Case Alignment:
    • Are dynamic query filters a core requirement (e.g., admin dashboards, public APIs), or can they be handled via simpler route parameters?
    • Will filters need to support complex logic (e.g., multi-table joins, full-text search) beyond basic where clauses?
  2. Validation Strategy:
    • How will filter inputs be validated? Will this package replace, complement, or extend existing validation (e.g., Form Requests)?
  3. Testing Scope:
    • What percentage of Eloquent queries will use this package? High usage warrants comprehensive filter-class testing.
  4. Future-Proofing:
    • Does the team plan to adopt Laravel 10+ features (e.g., model macros) that might interact with this package?
  5. Alternatives:

Integration Approach

Stack Fit

  • Laravel Ecosystem: Native support for Eloquent, Laravel’s service container, and Octane makes this a first-class citizen in Laravel stacks.
  • API-First Projects: Ideal for:
    • RESTful APIs with client-driven filtering (e.g., /users?role=admin&active=true).
    • GraphQL backends where resolvers need dynamic data fetching.
  • Admin Panels: Reduces boilerplate in Laravel Nova/Vue/React admin interfaces.
  • Non-Fit: Avoid for:
    • Non-Laravel PHP projects.
    • Applications using raw SQL or non-Eloquent query builders.

Migration Path

  1. Pilot Phase:
    • Start with a single high-impact endpoint (e.g., /products with filters for category, price_range).
    • Compare development time vs. manual query construction in controllers.
  2. Generator Adoption:
    • Run php artisan make:query-filter PostFilter for critical models.
    • Customize config/query_filters.php to match project structure (e.g., app/Filters).
  3. Incremental Rollout:
    • Replace simple where clauses in controllers with filter classes.
    • Use trait HasQueryFilters in models for global filter support (if enabled).
  4. Validation Integration:
    • Extend filter classes to use existing Form Requests or add dedicated validation (e.g., FilterRequest).

Compatibility

  • Laravel Versions: Supports 5.5+ (core) and 8.0+ (Octane). Test thoroughly on target version (e.g., 9.x/10.x).
  • PHP Versions: Requires PHP 7.4+ (aligns with Laravel’s minimum).
  • Dependencies: No major conflicts expected; ensure no version skew with other packages (e.g., illuminate/database).
  • Customization: Override default behavior via:
    • Service provider binding (e.g., custom filter resolver).
    • Publishing config files for global adjustments.

Sequencing

  1. Setup:
    • Install package + publish config.
    • Configure filter class path and default namespace.
  2. Development:
    • Generate filter classes for 1–2 critical models.
    • Implement basic rules (e.g., equals, contains, between).
  3. Testing:
    • Write unit tests for filter classes (mock Request and Builder).
    • Test edge cases (e.g., invalid parameters, empty filters).
  4. Deployment:
    • Roll out to non-critical endpoints first.
    • Monitor query performance and error logs.
  5. Optimization:
    • Add caching for frequently used filters (e.g., Cache::remember).
    • Optimize complex queries (e.g., select specific columns).

Operational Impact

Maintenance

  • Pros:
    • Reduced Boilerplate: Filter classes centralize query logic, making it easier to update (e.g., adding a new status filter).
    • Consistent Patterns: Enforces a standardized way to handle query parameters across the codebase.
  • Cons:
    • New Abstraction Layer: Developers must learn filter class conventions (e.g., rule methods, chaining).
    • Tooling Dependency: Relies on Artisan generator; customization may require package updates.

Support

  • Debugging:
    • Filter-specific errors (e.g., invalid rule syntax) are easier to isolate than scattered where clauses.
    • Use dd($query) in filter classes to inspect generated SQL.
  • Documentation:
    • Internal docs should cover:
      • Filter class structure (e.g., apply($query, $request)).
      • Rule method signatures (e.g., dateRange($query, $request, $field)).
      • Example filter implementations for common use cases.
  • Community:
    • Limited dependents (0) suggests niche adoption; rely on GitHub issues or Laracasts for troubleshooting.

Scaling

  • Performance:
    • Pros: Centralized filters enable query optimization (e.g., caching, indexing) at the model level.
    • Cons: Poorly optimized filters (e.g., LIKE %term%) can scale poorly. Mitigate with:
      • Database indexes on filtered columns.
      • Query caching (e.g., Cache::tags('filters')).
      • Pagination (SimplePaginator) for large datasets.
  • Concurrency:
    • Octane-compatible, but test under load to ensure filter resolution doesn’t become a bottleneck.
    • Consider lazy-loading filter classes if resolution is slow.

Failure Modes

Failure Scenario Impact Mitigation
Invalid filter parameter Silent failure or SQL errors Validate inputs in filter classes or use Form Requests.
Unhandled exception in filter rule 500 errors for affected endpoints Wrap filter logic in try-catch; log errors.
Database index missing Slow queries under load Add indexes for frequently filtered columns.
Filter class conflicts Overwritten rules or logic Use unique namespaces (e.g., App\Filters).
Package update breaks compatibility Feature regression Pin version in composer.json; test updates.

Ramp-Up

  • Developer Onboarding:
    • Time Estimate: 1–2 hours to understand filter classes vs. manual queries.
    • Training:
      • Show side-by-side examples (old: controller where clauses vs. new: filter classes).
      • Demonstrate generator usage (php artisan make:query-filter).
  • Team Adoption:
    • Start with a "filter champion" to document patterns and resolve early issues.
    • Pair programming for complex filters (e.g., multi-table joins).
  • Documentation Needs:
    • Code Examples: Filter classes for common models (e.g., UserFilter, PostFilter).
    • Decision Records: Why filters were chosen over alternatives (e.g
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours