Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Saring Laravel Package

laraditz/saring

Saring is a simple Eloquent model filtering package for Laravel and Lumen. Add the Filterable trait to models, create per-model filter classes (e.g., UserFilter), optionally whitelist filterable fields, and call Model::filter($request->all()).

View on GitHub
Deep Wiki
Context7

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed