PHP code example of intraset / laravel-filter

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

    

intraset / laravel-filter example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Intraset\LaravelFilter\HasFilter;

class User extends Model
{
    use HasFilter;
}



namespace App\Http\Filters;

use Illuminate\Database\Eloquent\Builder;
use Intraset\LaravelFilter\Filter;

class UserFilter extends Filter
{
    /**
     * Apply filters.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function apply(Builder $builder)
    {
        parent::apply($builder);

        $builder->orderBy('name');

        return $builder;
    }

    /**
     * Name filter.
     *
     * @param  string|null  $value
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function name($value = null)
    {
        $this->builder->where('name', $value);

        return $this->builder;
    }
}

public function index(Request $request, UserFilter $filter)
{
    $users = User::filter($filter)->get();

    return $users;
}