PHP code example of spinen / laravel-browser-filter

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

    

spinen / laravel-browser-filter example snippets


'providers' => [
    // ...
    Spinen\BrowserFilter\FilterServiceProvider::class,
];

    ->withMiddleware(function (Middleware $middleware) {
        // ...
        $middleware->web(append: [
            // ...
            \Spinen\BrowserFilter\Stack\Filter::class,
        ]);
        // ...
    })

    ->withMiddleware(function (Middleware $middleware) {
        // ...
        $middleware->alias([
            // ...
            'browser.allow' => \Spinen\BrowserFilter\Route\AllowFilter::class,
            'browser.block' => \Spinen\BrowserFilter\Route\BlockFilter::class,
        ]);
        // ...
    })

    protected $middlewareGroups = [
        'web' => [
            // ..
            \Spinen\BrowserFilter\Stack\Filter::class,
        ],
        // ..

    protected $routeMiddleware = [
        // ..
        'browser.allow' => \Spinen\BrowserFilter\Route\AllowFilter::class,
        'browser.block' => \Spinen\BrowserFilter\Route\BlockFilter::class,

    // This is only a simple example.  You would probably want to route to a controller with a view.
    Route::get('incompatible_browser', ['as' => 'incompatible_browser', 'uses' => function() {
        return "You are using a blocked browser.";
    }]);

    Route::get('tablet_page', [
        'middleware' => 'browser.allow:Tablet',
        'uses'       => function () {
            return "Special page that is only accessible to tablets";
        }
    ]);

    Route::get('ie_is_blocked_page', [
        'middleware' => 'browser.block:Other/Ie',
        'uses'       => function () {
            return "Special page that is only accessible to non IE browsers on Desktops";
        }
    ]);

    $rule = [
        'Mobile' => '*',
        'Other' => [
            'Ie' => [
                '<' => '10',
                '>' => '13',
            ],
        ],
        'Tablet' => '*',
    ]
bash
$ php artisan vendor:publish --provider="Spinen\BrowserFilter\FilterServiceProvider"