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

Filters Laravel Package

adimeo-data-suite/filters

Laravel package providing a filter suite for building and applying query filters to data sets. Helps structure filter definitions and plug them into requests for consistent, reusable filtering in your application.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Filtering Abstraction: The package provides a declarative way to implement filtering logic (e.g., for APIs, queries, or collections) via a fluent interface, which aligns well with Laravel’s Eloquent and API resource patterns. It could reduce boilerplate in:
    • API Controllers: Dynamic query filtering (e.g., ?filter[price][gt]=100).
    • Eloquent Scopes: Reusable, composable filter logic across models.
    • Collection Manipulation: Client-side or server-side filtering of arrays/collections.
  • Symfony CSS Selector Dependency: Leverages symfony/css-selector for path-based filtering (e.g., filter[user.address.city]=Paris), which is intuitive for nested data (e.g., JSON APIs, Eloquent relationships). This is a strong fit for Laravel’s nested resource structures.
  • Commons Dependency: Assumes adimeo-data-suite/commons (undocumented) provides shared utilities (e.g., validation, type handling). Risk: Tight coupling to an unproven package with no adoption.

Integration Feasibility

  • Laravel Ecosystem Compatibility:
    • Eloquent: Can wrap Builder methods to inject dynamic filters (e.g., Model::filter($request)->get()).
    • API Resources: Filter responses before serialization (e.g., Resource::collection($filteredData)).
    • Form Requests: Validate and apply filters in AuthorizesRequests or ValidatesRequests.
  • Guzzle Dependency: Unused in the package’s core filtering logic. Redundant unless the package evolves to include HTTP-based filtering (e.g., scraping).
  • Service Provider: Likely requires a custom facade or service container binding to integrate with Laravel’s DI system.

Technical Risk

  • Undocumented Assumptions:
    • adimeo-data-suite/commons dependency is a black box. Could introduce hidden dependencies or breaking changes.
    • No examples of Laravel-specific integrations (e.g., Eloquent, API Resources).
  • Performance:
    • Nested Filtering: CSS selectors on Eloquent queries may generate inefficient SQL (e.g., WHERE JSON_EXTRACT(path, '$.user.address.city') = 'Paris'). Risk of N+1 queries if not optimized.
    • Collection Filtering: Client-side filtering (e.g., JavaScript) shifts load to the client; server-side filtering may still require eager loading.
  • Security:
    • Injection Risks: Dynamic CSS selectors could enable path traversal if not sanitized (e.g., filter[user../../../secret]=true). Requires input validation.
    • Mass Assignment: Filter parameters must be whitelisted to prevent unauthorized field access.

Key Questions

  1. Use Case Clarity:
    • Is this for API filtering (e.g., GraphQL-like queries), admin panels, or client-side state management?
    • Does it replace Laravel’s built-in features (e.g., where clauses, API resource filtering) or augment them?
  2. Performance Trade-offs:
    • How will nested filters impact query performance? Are there benchmarks for large datasets?
    • Is client-side filtering an option, or is server-side filtering mandatory?
  3. Maintenance Overhead:
    • How will this package evolve alongside Laravel (e.g., PHP 8.2+ features, Symfony 6+ dependencies)?
    • Is there a fallback mechanism if adimeo-data-suite/commons fails?
  4. Security Validation:
    • Are there built-in guards against malicious filter inputs (e.g., SQLi, path traversal)?
    • How does it handle sensitive fields (e.g., filter[user.password])?

Integration Approach

Stack Fit

  • Laravel-Specific Layers:
    • Request Handling: Integrate with Illuminate\Http\Request to parse filter queries (e.g., filter[field][operator]=value).
    • Middleware: Apply filtering globally (e.g., FilterMiddleware for API routes).
    • Service Container: Bind the filter service to Laravel’s container for dependency injection.
  • Complementary Packages:
    • API: Pair with laravel-api or spatie/laravel-query-builder for advanced query support.
    • Validation: Use laravel-validator to sanitize filter inputs before processing.
    • Caching: Cache filtered query results if performance is critical (e.g., Illuminate\Support\Facades\Cache).
  • Frontend Sync:
    • If using client-side filtering, ensure the package generates consistent filter syntax for frontend frameworks (e.g., Vue/React).

Migration Path

  1. Proof of Concept (PoC):
    • Implement a single route/controller to test filtering logic (e.g., GET /products?filter[price][gt]=50).
    • Compare performance against native Eloquent queries.
  2. Incremental Rollout:
    • Start with non-critical endpoints (e.g., admin panels, internal tools).
    • Gradually replace manual where clauses with the package’s fluent interface.
  3. Hybrid Approach:
    • Use the package for complex filters (e.g., nested JSON) while keeping simple filters native.
    • Example:
      // Native Laravel
      $query->where('price', '>', $request->input('min_price'));
      
      // Package for nested filters
      $query->filter($request->input('filter', []));
      

Compatibility

  • Laravel Versions:
    • Test against Laravel 9.x/10.x (PHP 8.0+). May require adjustments for older versions.
    • Check for conflicts with symfony/css-selector (v6+) and guzzlehttp/guzzle (unused but required).
  • Database Support:
    • MySQL/PostgreSQL: Works with JSON columns or relational queries.
    • SQLite: May struggle with complex JSON paths (e.g., JSON_EXTRACT).
    • NoSQL: Not applicable; package is SQL-centric.
  • Alternative Libraries:

Sequencing

  1. Phase 1: Core Integration
    • Bind the package to Laravel’s service container.
    • Create a filter service to handle request parsing and query building.
  2. Phase 2: Eloquent Integration
    • Extend Illuminate\Database\Eloquent\Builder with a filter() method.
    • Example:
      namespace App\Extensions;
      use Adimeo\DataSuite\Filters\Filter;
      use Illuminate\Database\Eloquent\Builder;
      
      class FilterableBuilder extends Builder {
          public function filter(array $filters): static {
              return (new Filter())->apply($this, $filters);
          }
      }
      
  3. Phase 3: API/Resource Layer
    • Add filtering to Illuminate\Http\Resources\Json\Resource or Json\JsonResource.
    • Example:
      public function toArray($request) {
          $data = parent::toArray($request);
          return Filter::apply($data, $request->input('filter', []));
      }
      
  4. Phase 4: Validation & Security
    • Implement whitelisting for allowed filter fields.
    • Add middleware to validate filter inputs before processing.

Operational Impact

Maintenance

  • Dependency Risks:
    • adimeo-data-suite/commons: No GitHub activity or documentation. Mitigation:
      • Fork and maintain a Laravel-compatible version.
      • Extract only the needed functionality (e.g., validation) into a local package.
    • Symfony CSS Selector: Stable but may require updates for Laravel’s PHP version.
  • Upgrade Path:
    • Monitor for breaking changes in symfony/css-selector (e.g., PHP 8.2+ features).
    • Semantic Versioning: Ensure the package follows ^1.0.0 to avoid major version lock-in.
  • Local Overrides:
    • Extend the package via traits or decorators to customize behavior (e.g., add Laravel-specific query optimizations).

Support

  • Debugging Challenges:
    • Complex Filter Chains: Debugging nested CSS selectors (e.g., filter[user.addresses[*].city]) may require deep inspection of the filter tree.
    • Performance Bottlenecks: Slow queries due to unoptimized JSON paths. Tools:
      • Use Laravel Debugbar to profile filtered queries.
      • Add logging for filter application steps.
  • Community Resources:
    • Lack of Adoption: No stars/dependents means limited community support. Workarounds:
      • Open issues on the repo for Laravel-specific features.
      • Contribute back to the package if it proves valuable.
  • Vendor Lock-in:
    • Custom filter syntax may require documentation for frontend teams.
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle