| Package Data | |
|---|---|
| Maintainer Username: | raditzfarhan |
| Maintainer Contact: | raditzfarhan@gmail.com (Raditz Farhan) |
| Package Create Date: | 2020-05-09 |
| Package Last Update: | 2022-01-19 |
| Language: | PHP |
| License: | MIT |
| Last Refreshed: | 2025-11-04 15:05:38 |
| Package Statistics | |
|---|---|
| Total Downloads: | 136 |
| Monthly Downloads: | 0 |
| Daily Downloads: | 0 |
| Total Stars: | 0 |
| Total Watchers: | 1 |
| Total Forks: | 0 |
| Total Open Issues: | 0 |
A simple eloquent model filter for Laravel and Lumen.
Via Composer
$ composer require laraditz/saring
Add filterable trait to your model as below snippet:
use Laraditz\Saring\Filterable;
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use Filterable;
...
}
Create filter class under the App/Filters folder with <model_name>Filter format. For example for User model, you will need to create UserFilter class.
Below snippet shows how the UserFilter could look like:
namespace App\Filters;
use Laraditz\Saring\Filter;
class UserFilter extends Filter
{
public function name($value)
{
$this->where('name', 'LIKE', $value);
}
public function email($value)
{
$this->where('email', 'LIKE', "%$value%");
}
}
If you want to have more control on which attributes can be filtered, you can add filterable array to you model:
protected $filterable = [
'name', 'email'
];
In your controller, call filter method and pass the input data to use the filter that you have created.
$users = User::filter($request->all())->get();
That's it!
MIT. Please see the license file for more information.