Download the PHP package travelbuild/eloquent-filterable without Composer
On this page you can find all versions of the php package travelbuild/eloquent-filterable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download travelbuild/eloquent-filterable
More information about travelbuild/eloquent-filterable
Files in travelbuild/eloquent-filterable
Package eloquent-filterable
Short Description Use dynamically Eloquent scopes for search process
License MIT
Informations about the package eloquent-filterable
Eloquent Filterable
With this package, you can call local scopes with filter
scope method.
Installation
PHP 7.1.3+ or HHVM, and Composer are required.
To get thepackage, simply add the following line to the require block of your composer.json
file:
You'll then need to run composer install or composer update to download it and have the autoloader updated. Or use to shortcut installed through terminal:
Usage
Each model must be implement the Filterable
trait.
Then, you can define local scopes in your model. If you need help to local scopes, please follow the Laravel documentation.
And finally, you must be define usable local scopes to the filterable
property in your model if you need. Why need it? We don't want some scopes to be used by the client.
if you want all scopes to be usable to the client, do not define filterable
property or define as follows:
This way is not recommended. Take control, access to all scopes may be risky.
That's it. Now, you can call dynamically all callable scopes with filter
scope.
Real World Example
We needed this package to quickly respond HTTP requests. Our client send to us some conditions using by search endpoint. We wanted to handle these filter conditions dynamically for simplicity and reusability.
Create a new route for post search in routes/api.php
:
Define model and filterable local scopes:
Now, the client may be send to server some search conditions. Here is some example endpoints:
Our model will be apply the filter when exists local scope.
Contributing
Love innovation and simplicity. Please use issues all errors or suggestions reporting. Follow the steps for contributing:
- Fork the repo.
- Follow the Laravel Coding Style.
- If necessary, check your changes with unittest.
- Commit all changes.
- Push your commit and create a new PR.
- Wait for merge the PR.
Unit Test
Please create your tests and check before PR. Use the command:
License
Eloquent Filterable is licensed under The MIT License (MIT).