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. Just call filter() on a model query, then let clients apply complex conditions via URL query parameters (e.g., filters[title][$contains]=...). Great for clean, flexible APIs.

View on GitHub
Deep Wiki
Context7

An elegant way to filter and sort queries in Laravel

Frequently asked questions about Laravel Purity
How do I add filtering to an Eloquent query with Laravel Purity?
Simply call `filter()` on your Eloquent query builder. For example, `Post::filter()->get()` enables filtering via URL params like `?filters[title][$contains]=Laravel`. No additional setup is required for basic usage.
Does Laravel Purity support sorting in addition to filtering?
Yes, it includes built-in sorting. Use `sort()` alongside `filter()` or configure default sortable fields in your model. Sorting is controlled via URL params like `?sort=-created_at` for descending order.
Which Laravel versions does Laravel Purity support?
The package is designed for Laravel 10+ and requires PHP 8.1+. Check the [Packagist page](https://packagist.org/packages/abbasudo/laravel-purity) for the latest version compatibility details.
Can I restrict which fields are filterable/sortable for security?
Absolutely. Define `$filterFields` and `$sortFields` in your model to explicitly allow only specific fields. This prevents accidental exposure of sensitive data like passwords or internal IDs.
How does Laravel Purity handle complex filtering, like nested relations?
It supports filtering on relations (e.g., `filters[tags.name][$eq]=laravel`) but does not natively handle deeply nested relations like `user.posts.tags.name`. For advanced cases, use custom filters or manual SQL.
Will this package work with Livewire for real-time filtering?
Yes, Laravel Purity integrates seamlessly with Livewire. The URL-based query parameters work out of the box, allowing real-time filtering without page reloads in Livewire components.
Are there performance concerns with many filters applied simultaneously?
Dynamic query building can introduce SQL complexity. Profile your queries to ensure no N+1 issues arise. Use `select()` or `with()` to optimize large datasets, and restrict filterable fields to minimize overhead.
How do I test queries with filters and sorting?
Use Laravel’s testing tools to simulate URL params. For example, `Post::filter()->where('title', 'like', '%Purity%')->get()` mimics a filtered query. Test edge cases like invalid operators or empty filters.
What happens if an invalid filter operator is used (e.g., `$invalid`)?
By default, invalid operators are ignored silently. Enable `throw_exceptions` in config to log or handle errors explicitly. Always validate custom filters manually to prevent SQL injection risks.
Are there alternatives to Laravel Purity for Eloquent filtering?
Yes, alternatives include `spatie/laravel-query-builder`, `archtechx/telescope-filters`, or custom solutions using `where()` clauses. Laravel Purity stands out for its simplicity, Livewire integration, and expressive URL-based syntax.
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.
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
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope