PHP code example of baraveli / laravel-query-filters

1. Go to this page and download the library: Download baraveli/laravel-query-filters 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/ */

    

baraveli / laravel-query-filters example snippets




namespace App\Filters;

use Illuminate\Database\Eloquent\Builder;
use Baraveli\QueryFilters\QueryFilter;

class UsersFilters extends QueryFilter
{        
    /**
     * per_Page
     *
     * @param  mixed $number
     * @return void
     */
    public function per_Page($number = 5)
    {
        return $this->builder->paginate($number);
    }

    /**
     * search
     *
     * @param  mixed $search
     * @return Builder
     */
    public function search($search) : Builder
    {
        return $this->builder->where('name','like', '%' . $search .'%');
    }

    
}




namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Baraveli\QueryFilters\Filterable;

class User extends Authenticatable
{
    use HasFactory, Notifiable, Filterable;
}


Route::get('users', function(UsersFilters $usersfilter){
    return User::filter($usersfilter)->get();
});