fugazi-code/laravel-eloquent-filter

A custom filter for your Eloquent Builder

1.0.2 2023-01-21 01:18 UTC

This package is auto-updated.

Last update: 2024-04-21 03:59:00 UTC


README

Latest Version on Packagist Total Downloads

This is where your description should go. Take a look at contributing.md to see a to do list.

Installation

Via Composer

$ composer require fugazi-code/laravel-eloquent-filter

Usage

Change log

Please see the changelog for more information on what has changed recently.

Install

$ php artisan make:filter UserFilter

Filter Class

<?php

namespace App\Http\Controllers\Filters;

use FugaziCode\Filter\Filter;

class UserFilter extends Filter
{
    public function email($value)
    {
        $this->query->where('email', 'like', "%$value%");
    }

    public function permanent($value)
    {
        $this->query->whereHas('address', function($query) use ($value) {
            $query->where('permanent', 'like', "%$value%");
        });
    }
}

Eloquent Implementation

Route::get('/', function () {
    return User::query()->with(['address'])->filter(new UserFilter)->get();
});

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email author@email.com instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.