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
Laravel Purity

Laravel Purity Laravel Package

abbasudo/laravel-purity

Laravel Purity adds elegant filtering and sorting to Eloquent queries via a simple filter() method. Let frontend users drive complex query conditions using URL query string parameters (e.g., filters[title][$contains]=Purity), with minimal boilerplate.

View on GitHub
Deep Wiki
Context7

Laravel Purity is an elegant package for adding filtering and sorting to Laravel Eloquent queries using simple URL query string parameters. By appending filter() to a query, you enable frontend-friendly, consistent, and maintainable query customization without writing repetitive conditional logic.

It’s built to keep controllers lean while supporting complex filtering rules in a clean, expressive way—ideal for APIs and admin panels.

  • Add filtering/sorting with a single Model::filter() call
  • Query via URL params (e.g. filters[field][$contains]=...)
  • Designed for complex, composable Eloquent constraints
  • Helps centralize and standardize query logic
  • Works cleanly for API-driven UIs and data tables
Frequently asked questions about Laravel Purity
How do I enable filtering/sorting on a Laravel Eloquent model with Laravel Purity?
Add the `Filterable` and `Sortable` traits to your model, then call `Model::filter()->sort()` in your controller. The package automatically parses URL query params like `filters[field][$contains]=value` and applies them to your query.
What Laravel and PHP versions does Laravel Purity support?
Laravel Purity is optimized for Laravel 10+ and requires PHP 8.1+. Check the [documentation](https://abbasudo.github.io/laravel-purity/) for minor version compatibility details, as breaking changes may occur in major releases.
Can I use Laravel Purity with Livewire for real-time filtering?
Yes, Laravel Purity integrates seamlessly with Livewire. Bind your component’s `$filters` property to the query params, and the package will sync filtering logic automatically, enabling dynamic updates without full page reloads.
How does Laravel Purity handle complex nested relations (e.g., `user.posts.tags.name`)?
The package supports relation fields via dot notation (e.g., `filters[posts.tags.name][$contains]=...`). However, deeply nested relations may impact performance—optimize with eager loading (`with()`) or limit relation depth in your `filterFields` configuration.
Does Laravel Purity work with API resources or GraphQL?
Yes, it’s API-first designed. Use it with Laravel’s API resources to return filtered/sorted data, or integrate with GraphQL by mapping query params to GraphQL arguments. The package remains agnostic to your frontend framework.
How do I customize or add new filter operators (e.g., `$in` for array fields)?
Extend the `Filterable` trait or create custom filter classes. Override the `getFilterOperators()` method in your model or use the `addFilterOperator()` helper to register new operators like `$in` for array comparisons.
What’s the performance impact of filtering large datasets (e.g., 100K+ records)?
Dynamic queries can introduce overhead, especially with complex filters. Mitigate this by indexing filtered columns, using `limit()`/`offset()` for pagination, and leveraging the package’s built-in eager loading optimizations for relations.
How does Laravel Purity handle security risks like SQL injection or malicious input?
The package sanitizes input by default but relies on Laravel’s Eloquent query builder for security. For stricter control, validate filter operators/values in middleware or use the `purity.php` config to enable exception logging instead of silent failures.
Can I integrate Laravel Purity with existing custom Eloquent scopes or global scopes?
Yes, Purity respects existing scopes. Use the `scopes` key in your `filterFields` config to map custom scopes to URL params (e.g., `filters[status][$published]`). Global scopes are automatically applied unless excluded in the config.
What alternatives to Laravel Purity exist, and how does it compare?
Alternatives include `spatie/laravel-query-builder` (more low-level) and `archtechx/boom` (focused on admin panels). Purity stands out for its URL-param-driven design, Livewire integration, and minimal boilerplate—ideal for APIs and dynamic UIs.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport