PHP code example of onvardgmbh / laravel-filters

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

    

onvardgmbh / laravel-filters example snippets



return [

    . . .

    /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
    | The service providers listed here will be automatically loaded on the
    | request to your application. Feel free to add your own services to
    | this array to grant expanded functionality to your applications.
    |
    */

    'providers' => [

        . . .

        /*
         * The FilterServiceProvider needs to be inserted BEFORE App\Providers\RouteServiceProvider::class,
         */
        Onvard\Filter\FilterServiceProvider::class,

        App\Providers\RouteServiceProvider::class,
    ],

    . . .

];


. . .

protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],

        'api' => [
            'throttle:60,1',
        ],

        'filter' => [
            \Onvard\Filter\Middleware\ApplyFilters::class,
        ],

. . .

    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
        'filter' => \Onvard\Filter\Middleware\ApplyFilters::class,
    ];

. . .

. . .

Route::group(['middleware' => ['web','filter'], 'filter' => [ 'after' => [ 'minifyHTML' ] ] ],function () {
    Route::get( '/',
        [
            'middleware' => ['filter'],
            'filter' => [
                'before' => [
                    'functionName'
                ],
                'after' => [
                    'functionName'
                ]
            ],
            function () {
                return view('welcome');
            }
        ]
    );
});

. . .

php artisan vendor:publish --provider="Onvard\Filter\FilterServiceProvider" --tag=filters