PHP code example of mnabialek / laravel-eloquent-filter

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

    

mnabialek / laravel-eloquent-filter example snippets

   
   composer 

use \Mnabialek\LaravelEloquentFilter\Traits\Filterable;

class User extends Authenticatable
{
    use \Mnabialek\LaravelEloquentFilter\Traits\Filterable;



namespace App\Filters;

use Mnabialek\LaravelEloquentFilter\Filters\SimpleQueryFilter;

class UserFilter extends SimpleQueryFilter
{
    protected $simpleFilters = ['id','created_at'];
    
    protected $simpleSorts = ['id','email','created_at'];
}

$users = User::get();

$users = User::filtered(\App::make(\App\Filters\UserFilter::class))->get();

protected function applyCreatedAt($value)
{
    $this->query->whereRaw('DATE(created_at) = ? ', [$value]);
}
 
protected function applySortId($order)
{
   $this->query->orderBy('id',$order)->orderBy('email','asc');
}