- 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.