PHP code example of miracuthbert / laravel-eloquent-filters

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

    

miracuthbert / laravel-eloquent-filters example snippets


Miracuthbert\Filters\EloquentFiltersServiceProvider::class

$users = User::filter($request)->get();

$users->appends(filters_query());

    /**
     * A list of filters.
     *
     * @var array
     */
    protected $filters = [
         'name' => NameFilter::class,
         'email' => EmailFilter::class,
         'created' => CreatedOrder::class,
    ];

    /**
     * A list of default filters.
     *
     * @var array
     */
    protected $defaultFilters = [
         'created' => 'desc',
    ];

    // constructor

    if ($request->hasAny('cancelled', 'completed')) {
        $this->defaultFilters = [
            'upcoming' => 'false'
        ];
    }

php artisan vendor:publish --provider=Miracuthbert\Filters\EloquentFiltersServiceProvider --tag=filters-config

php artisan filter:model {name}

// example
php artisan filter:make UserFilters

// within specific namespace
php artisan filter:make Users\\UserFilters