PHP code example of htetoozin / eloquent-filter

1. Go to this page and download the library: Download htetoozin/eloquent-filter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

htetoozin / eloquent-filter example snippets




namespace App\Filters;

use HtetOoZin\EloquentFilter\Filters\Filter;

class UserFilter extends Filter
{
    /**
     * Register filter properties
     */
    protected $filters = ['keyword'];


    /**
     * Filter by keyword.
     */
    public function keyword($value)
    {
        return $this->builder->where('name', 'like', "%{$value}%");
    }
}




class User extends Model
{
    public function scopeFilter($query, $filter)
    {
        $filter->apply($query);
    }
}




use App\Filters\UserFilter;

class UserController extends Controller
{
    public function index(UserFilter $filter)
    {
        return User::filter($filter)->get();
    }
}