Download the PHP package pointybeard/laravel-filterable-model without Composer
On this page you can find all versions of the php package pointybeard/laravel-filterable-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download pointybeard/laravel-filterable-model
More information about pointybeard/laravel-filterable-model
Files in pointybeard/laravel-filterable-model
Package laravel-filterable-model
Short Description Add filtering via http request query params to eloquent models
License MIT
Informations about the package laravel-filterable-model
Laravel Filterable Model
Add filtering via http request query params to Eloquent models in Laravel
Installation
Usage
Extend your Eloquent models with Pointybeard\FilterableModel\AbstractFilterableModel
and then use the trait Pointybeard\FilterableModel\Traits\FilterableTrait
. This will add a new scope called filter
, as well as the following methods, to your model:
getFilterable()
getSortable()
getSortByDefault()
getSortOrderDefault()
Then, add protected properties $filterable
, $sortable
, $sortByDefault
, and $sortOrderDefault
to control the behaviour of filtering. E.g.
Finally, you can use the ->filter()
scope to filter results by passing an instance of Filter
. E.g.
Alternatively, use the Filter::fromRequest()
method to build a filter from request query params, e.g. in your controllers like so:
By default, all comparisons are done by injecting an equals (=
) where clause into the database calls. To use other comparisons, or add more complex logic, create a new class that extends Pointybeard\FilterableModel\Filter
and add your own methods. For example, to use a LIKE
comparison for your tag
field and a boolean comparison for is_published
:
Contributing
We encourage you to contribute to this project. Please check out the Contributing documentation for guidelines about how to get involved.
Support
If you believe you have found a bug, please report it using the GitHub issue tracker.
Authors
License
"Laravel Filterable Model" is released under the MIT License. See LICENCE for details.
All versions of laravel-filterable-model with dependencies
illuminate/database Version ^9.17 || ^10.23
illuminate/http Version ^9.17 || ^10.23
illuminate/support Version ^9.17 || ^10.23
spatie/laravel-data Version ^3.9
webmozart/assert Version ^1.11