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 Filter Laravel Package

laravie/query-filter

Laravie Query Filter adds a clean, reusable way to filter Eloquent queries from request input. Define filter classes and apply them to models to handle searching, sorting, and conditional constraints without cluttering controllers or repositories.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Query Abstraction: Remains a strong fit for Laravel’s query builder and repository patterns, particularly for applications with complex filtering needs (e.g., dashboards, APIs). The declarative approach reduces boilerplate while maintaining readability.
  • Separation of Concerns: Continues to encourage decoupling of filtering logic from controllers/services, improving modularity. Ideal for shared filter logic across APIs/admin panels.
  • Composability: Supports dynamic filter chaining, critical for APIs requiring ad-hoc filtering. No changes to this core functionality in v4.1.0.
  • Laravel 11 Support: Aligns with the latest Laravel version, ensuring long-term compatibility for new projects or migrations. This reduces technical debt for teams adopting Laravel 11 early.

Integration Feasibility

  • Laravel Native: Continues to leverage Laravel/Eloquent seamlessly, with no friction for integration. The addition of Laravel 11 support broadens compatibility for new deployments.
  • Dependency Lightweight: Still requires only Laravel and PHP ≥8.0, with no heavy external dependencies. Risk of version conflicts remains low.
  • Customization Points:
    • Custom filter classes and extensions remain supported.
    • No breaking changes to the core API in v4.1.0.
  • Testing: Unit and integration testing strategies remain unchanged, though Laravel 11’s updated testing utilities (e.g., Testing facade improvements) may simplify test writing.

Technical Risk

  • Request Parsing: Security and validation risks (e.g., SQL injection, malformed input) persist but are mitigated by Eloquent’s protections and Laravel’s validation tools. No changes to this in v4.1.0.
  • Performance:
    • Over-eager filtering (e.g., LIKE on large datasets) could still degrade performance. No new performance-related features or warnings in the release notes.
    • Lack of built-in pagination/limit handling remains a consideration for API endpoints.
  • Backward Compatibility:
    • Critical Update: Laravel 11 support may introduce subtle breaking changes if the package internally uses Laravel-specific features (e.g., service container binding syntax, route/model changes). Key Question: Does the package handle Laravel 11’s updated service provider booting or model binding?
    • No deprecations or breaking changes are noted in the release, but teams upgrading Laravel to v11 should verify compatibility.
  • Debugging: Complex filter chains may still obscure query generation. Laravel 11’s improved debugging tools (e.g., dd() enhancements) could help, but no package-specific changes are noted.

Key Questions

  1. Laravel 11 Compatibility:
    • Are there undocumented changes in the package’s internals (e.g., service provider booting, route/model handling) that could break after upgrading Laravel to v11?
    • Example: Does the package use booted() or register() in service providers, which may behave differently in Laravel 11?
  2. Filter Granularity (Unchanged):
    • How will filters be defined? Hardcoded or dynamically?
  3. Input Handling (Unchanged):
    • How will filter input be validated? Will Laravel’s built-in validation suffice, or are custom rules needed?
  4. Performance (Unchanged):
    • Are there plans to add pagination/limit handling or query caching to the package?
  5. Testing Strategy (Unchanged):
    • How will filter combinations be tested, especially with Laravel 11’s updated testing utilities?
  6. Extensibility (Unchanged):
    • Are custom filter types (e.g., geospatial) still supported without modification?
  7. API Contracts (Unchanged):
    • How will filter schemas be documented for consumers (e.g., OpenAPI)?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Laravel 11: Now fully supported, making this package a first-class choice for new Laravel 11 projects. Ideal for:
      • APIs with dynamic filtering (REST/GraphQL).
      • Admin panels (e.g., Backpack/Voyager) with search/filter UIs.
      • Services requiring reusable query filters.
    • Non-Laravel: Still not directly applicable to non-Laravel PHP apps.
  • Frontend: Pairs well with frontend frameworks (React/Vue) sending filter payloads via API requests. No changes to this integration path.

Migration Path

  1. Pilot Phase (Unchanged):
    • Start with a high-impact endpoint (e.g., a dashboard) and replace manual where() chains with the package’s filters.
  2. Incremental Adoption (Unchanged):
    • Refactor controllers/services to accept and parse filter input.
    • Gradually replace hardcoded queries with filter definitions.
  3. Middleware Integration (Unchanged):
    • Add middleware to parse/validate filter input early in the request lifecycle.
  4. Testing (Updated):
    • Leverage Laravel 11’s improved testing utilities (e.g., Testing facade, updated assertions) to streamline test writing.
    • Example:
      // Laravel 11-style test
      public function test_filtered_query()
      {
          $response = $this->get('/users', ['filters' => ['status' => 'active']]);
          $response->assertOk()->assertJsonStructure(['data' => [[
              'id', 'name', 'status'
          ]]]);
      }
      
  5. Laravel 11 Upgrade Path:
    • Step 1: Upgrade Laravel to v11 in a staging environment.
    • Step 2: Test the package’s compatibility with critical endpoints.
    • Step 3: Update any package-specific configurations (e.g., service providers, route bindings) if Laravel 11 introduces breaking changes.
    • Step 4: Run integration tests to ensure no regressions.

Compatibility

  • Laravel Version:
    • Updated: Now officially supports Laravel 11. Teams using Laravel 10 or below should assess upgrade risks (see Technical Risk section).
    • PHP: Still requires PHP ≥8.0 (no changes).
  • Database: Unchanged compatibility with Eloquent-supported databases (MySQL, PostgreSQL, etc.).
  • Third-Party Packages:
    • Conflict Risk: Low if other packages don’t modify the query builder directly.
    • Synergy: Still complements packages like spatie/laravel-query-builder or archtechx/boom.
  • Custom Eloquent Models: Ensure models use standard Eloquent methods (no raw SQL overrides). No changes to this requirement.

Sequencing (Updated for Laravel 11)

  1. Upgrade Laravel to v11 (if not already on it):
    • Follow Laravel’s upgrade guide and test the package in a staging environment.
  2. Define Filter Schema (Unchanged):
    • Document allowed filters and their types (e.g., eq, gt, in).
  3. Implement Filter Classes (Unchanged):
    • Create custom filter classes for domain-specific logic.
  4. Integrate with Request Handling (Unchanged):
    • Parse and validate filter input using Laravel 11’s updated validation tools (e.g., new rule syntax).
  5. Apply Filters (Unchanged):
    • Modify query builder in repositories/services using the package’s apply() method.
  6. Add Frontend Support (Unchanged):
    • Update UI components to send filter payloads.
  7. Monitor and Optimize (Updated):
    • Use Laravel 11’s improved debugging tools (e.g., dd(), handle()) to log and optimize slow queries.
    • Example:
      // Laravel 11 debugging
      $query->toSql(); // Log the generated SQL
      dd($query->getQuery()->bindings); // Inspect bindings
      

Operational Impact

Maintenance

  • Pros (Unchanged):
    • Reduced boilerplate, consistent behavior, and easy updates.
  • Cons (Updated):
    • Laravel 11 Dependency: Teams must now maintain Laravel 11 compatibility, which may introduce new risks if the package has undocumented Laravel 11-specific behaviors.
    • Filter Logic Maintenance: Changes to filter rules still require updates across validation, frontend, and backend.
    • Debugging Complexity: Nested filters may still obscure query generation, but Laravel 11’s debugging tools can mitigate this.
  • Mitigation:
    • Document any Laravel 11-specific configurations or workarounds in a CONTRIBUTING.md file.
    • Use Laravel 11’s improved error handling (e.g., Problem exceptions) to surface filter-related issues.

Support

  • Proactive Measures (Updated):
    • Documentation: Update docs to reflect Laravel 11 support and any new requirements (e.g., service provider changes).
    • Error Handling: Leverage Laravel 11’s Problem exceptions for consistent error responses.
      // Example: Returning a Problem for invalid filters
      return Problem::validation(
          'Invalid filter input',
          response: null,
          status: '422',
          detail: 'The provided filters are invalid.'
      
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity