PHP code example of aidynmakhataev / laravel-filterable

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

    

aidynmakhataev / laravel-filterable example snippets


return [

    /*
    |--------------------------------------------------------------------------
    | Filters Configuration
    |--------------------------------------------------------------------------
    |
    */

    // namespace for the generated filters
    'namespace' =>  'App\Http\Filters'
];

namespace App\Http\Filters;

use AidynMakhataev\LaravelFilterable\BaseFilter;

class UserFilter extends BaseFilter
{
    public function gender($value)
    {
        return $this->builder->where('gender', $value);
    }

    public function working($value)
    {
        return $this->builder->where('is_working', $value);
    }
}

use AidynMakhataev\LaravelFilterable\Filterable;

class User extends Authenticatable
{
    use Filterable;

    /**
     * Filters attribute.
     *
     * @var array
     */
    protected $filters = \App\Http\Filters\UserFilter::class;

}

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

class UserController extends Controller
{
    public function index(Request $request)
    {
        $users = User::filter($request->all())->get();

        return response()->json($users);
    }
}
App\Http\Filters\UserFilter.php
config/filterable.php
$this->builder