New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

laraditz/saring

A simple eloquent model filter.
136
Install
composer require laraditz/saring
Latest Version:1.0.3
PHP:^7.2.5|^8.0
Laravel:6 · 7 · 8
License:MIT
Last Updated:Jan 19, 2022
Links: GitHub  ·  Packagist
Maintainer: raditzfarhan

Saring

Latest Stable Version Total Downloads License StyleCI

A simple eloquent model filter for Laravel and Lumen.

Installation

Via Composer

$ composer require laraditz/saring

Configuration

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'
];

Usage

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!

Credits

License

MIT. Please see the license file for more information.

Related Packages

laraditz/model-filter

A simple eloquent model filter.

443 0
dinkbit/filterable

Make your eloquent models filterable with ease.

34 6
raditzfarhan/laravel-sortable

Just a simple sortable behaviour for your Laravel and Lumen eloquent model.

209 0
tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

5,637,347 1,762
shiftonelabs/laravel-cascade-deletes

Adds application level cascading deletes to Eloquent Models.

901,465 165

Version History

Version Released PHP Laravel License
1.0.3 ^7.2.5|^8.0 ^6.0|^7.0|^8.0 MIT
1.0.2 ^7.2.5 ^7.0|^8.0 MIT
1.0.1 ^7.2.5 ^7.0|^8.0 MIT
1.0.0 ^7.2.5 ^7.0|^8.0 MIT