Download the PHP package grantholle/laravel-model-filters without Composer
On this page you can find all versions of the php package grantholle/laravel-model-filters. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download grantholle/laravel-model-filters
More information about grantholle/laravel-model-filters
Files in grantholle/laravel-model-filters
Package laravel-model-filters
Short Description A composable way to add filters to your model queries.
License MIT
Homepage https://github.com/grantholle/laravel-model-filters
Informations about the package laravel-model-filters
Laravel Model Filters
A composable way to filter Laravel models. This is not exhaustive, but it can add some basic filtering to your models.
Installation
You can install the package via composer:
By default, the package expects that filters are stored in the f
key of the request. You can change this by adding the environment variable MODEL_FILTERS_KEY
to your .env
file.
Usage
The first step is registering the filters for the desired model. In the model, add the HasFilters
trait and define the filters in the filters
method.
Once your filters are defined, you can get the list of the available filters by calling the availableFiltersToArray
on the model. This allows you to implement the frontend however you want.
The request should use the key defined in the environment (by default f
) along with the filter details. Take the following query string:
This will be expanded in the request to the following:
In your controller, you can call currentFilters
on the request to obtain the filters that should be applied to the model.
If you'd like to filter a model manually, the following structure should be used:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Grant Holle
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-model-filters with dependencies
spatie/laravel-package-tools Version ^1.14.0
illuminate/contracts Version ^10.0|^11.0