- How do I install dcblogdev/laravel-filters in a Laravel app?
- Install it with composer require dcblogdev/laravel-filters. The package targets Laravel 10+ and PHP 8.1+, and v2.0.3 widens the illuminate constraint to include Laravel 13. Run your test suite after updating; no service provider contract or base model is required beyond the package trait or interface.
- Does dcblogdev/laravel-filters support Laravel 13?
- v2.0.3 adds an explicit Laravel 13 compatibility statement in a patch release, so Composer should resolve it on Laravel 13. However, the maintainer's pinned laravel/framework at 10.48.29 and PHPUnit 9.6 suggest the CI matrix may not actually exercise Laravel 13. Treat the claim as something to verify in your own regression tests before relying on it.
- How do I define allowed filters for an Eloquent model?
- You define the set of allowed request parameters and map them to query constraints, typically by using the package trait on a model and declaring the filters it accepts. Only declared filters should be applied, which keeps arbitrary query-string keys from reaching the database. Check the README for the exact method names and supported filter types in your version.
- Can I save and reuse filters between requests?
- The package is built around saving and reusing query-based filters, so you can define a filter set once and apply it from multiple controllers or endpoints. Reuse is at the application-code level; if you need filters persisted per user, store those definitions yourself and feed them into the filter application. It does not impose a repository pattern or separate service provider contract.
- How does the package prevent SQL injection from query parameters?
- Because the package maps request parameters to Eloquent constraints, safety depends on whitelisting allowed filters and never interpolating raw request values into SQL. Define only the filters you intend to expose, validate or cast values before use, and avoid passing user-controlled column names or operators. The package reduces the surface area, but it does not replace normal Laravel validation and query review.
- Do I need to change my models or use a repository pattern?
- Adoption is opt-in: you add the package trait or interface to the models or endpoints where filtering is needed. There is no base model, repository pattern, or service provider contract required, so it will not dictate application structure. You can adopt it per model and bypass it where a custom query is clearer.
- How do I test filters in Laravel feature tests?
- Test filters as feature or unit tests by sending query parameters to an endpoint and asserting the resulting Eloquent results or generated SQL. Cover disallowed parameters, empty values, and combinations of filters, since those are the input-to-query edges most likely to leak or scan unexpectedly. If you use Laravel 13, include a regression run on that version rather than relying only on the package's published constraint.
- Is dcblogdev/laravel-filters maintained and safe for production?
- The package is a small single-maintainer project, and v2.0.3 is a patch release with no filtering API changes. Automated Dependabot updates are a positive health signal, but there is no second committer absorbing framework-support work, so plan for the possibility of owning a fork. For production, pin a version, review the input-to-query surface, and run your own compatibility tests.
- What are alternatives to dcblogdev/laravel-filters for filtering Eloquent queries?
- Alternatives include hand-written query scopes, Laravel request validation plus conditional clauses, or larger filter packages such as Spatie's query builder. dcblogdev/laravel-filters is a good fit when you want a lightweight, opt-in trait that maps allowed request parameters onto Eloquent constraints without a repository pattern. Choose a heavier package only if you need advanced filter persistence or a broader feature set.
- How do Laravel version constraints and Composer updates work with this package?
- v2.0.3 keeps the existing illuminate/* range and extends it upward to Laravel 13, so existing Laravel 10/11/12 installs should see no invalidating change. Composer resolution should be a no-op on those versions and will now resolve for Laravel 13. Confirm whether the Dependabot-bumped Symfony and CommonMark packages are in require or require-dev, because only runtime requirements affect your dependency graph.