All Projects → spinen → laravel-browser-filter

spinen / laravel-browser-filter

Licence: other
Laravel middleware to filter routes based on browser types & versions.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-browser-filter

laravel-geometry
SPINEN's Laravel wrapper over geoPHP
Stars: ✭ 36 (+80%)
Mutual labels:  laravel-5-package, spinen
laravel-garbage-man
Scheduled job to clean out Laravel's soft deleted records at configured interval
Stars: ✭ 33 (+65%)
Mutual labels:  laravel-5-package, spinen
Settings
A Laravel multi-tenant settings manager
Stars: ✭ 36 (+80%)
Mutual labels:  laravel-5-package
model-observers
Make model observers easy
Stars: ✭ 17 (-15%)
Mutual labels:  laravel-5-package
devtube
Laravel YouTube and Online Video viewing and download interface.
Stars: ✭ 30 (+50%)
Mutual labels:  laravel-5-package
vps
A laravel 5 package to easily create and maintain vps on digital ocean
Stars: ✭ 59 (+195%)
Mutual labels:  laravel-5-package
lara-block-io
A Laravel Package/Facade for the Block.io API
Stars: ✭ 22 (+10%)
Mutual labels:  laravel-5-package
cdek-sdk
SDK для СДЭК
Stars: ✭ 38 (+90%)
Mutual labels:  laravel-5-package
Base62
PHP Base62 encoder and decoder for integers and big integers with Laravel 5 support.
Stars: ✭ 16 (-20%)
Mutual labels:  laravel-5-package
maintenance-mode
An enhanced maintenance mode for Laravel.
Stars: ✭ 117 (+485%)
Mutual labels:  laravel-5-package
laravel-jira-rest-client
A Laravel interface for your Atlassians Jira application
Stars: ✭ 37 (+85%)
Mutual labels:  laravel-5-package
panichd
Ticketing system for Laravel 5.1 - 8.x. Allows to create new tickets via form only. Includes file attachments, ticket tags, filtering, scheduling and e-mail notifications.
Stars: ✭ 78 (+290%)
Mutual labels:  laravel-5-package
laravel-docweaver
Product documentation generation package for Laravel.
Stars: ✭ 36 (+80%)
Mutual labels:  laravel-5-package
domain-enforcement
Laravel 5+ Middleware to enforce a single domain on your application. e.g non-www. to www.
Stars: ✭ 25 (+25%)
Mutual labels:  laravel-5-package
laravel-backup-shield
🔒Password protection (and encryption) for your laravel backups.
Stars: ✭ 32 (+60%)
Mutual labels:  laravel-5-package
aws-rekognition
A Laravel Package/Facade for the AWS Rekognition API
Stars: ✭ 20 (+0%)
Mutual labels:  laravel-5-package
artisan-shortcuts
🍰 Register shortcuts to execute multiple artisan commands
Stars: ✭ 56 (+180%)
Mutual labels:  laravel-5-package
Laravel-Unsplash-Wrapper
A Laravel wrapper for Unsplash API's.
Stars: ✭ 21 (+5%)
Mutual labels:  laravel-5-package
smart-schema
A Laravel package to enable auto generation of forms
Stars: ✭ 18 (-10%)
Mutual labels:  laravel-5-package
LaravelFtp
Laravel FTP client
Stars: ✭ 15 (-25%)
Mutual labels:  laravel-5-package

SPINEN's Laravel Browser Filter

Latest Stable Version Latest Unstable Version Total Downloads License

This is a Laravel 5 middleware to filter routes based on browser types.

We specify the browsers that we are going to support at the beginning of a project, so this package makes sure that the visitor is using a supported browser.

Build Status

Branch Status Coverage Code Quality
Develop Build Status Code Coverage Scrutinizer Code Quality
Master Build Status Code Coverage Scrutinizer Code Quality

Prerequisites

NOTE: If you need to use PHP <7.2 or Laravel <5.2, please stay with version 1.x

As side from Laravel >= 5.5, there are 2 packages that are required:

  • mobiledetect - To get the user agent string. This package is not needed to get to the user agent string, but there are other features that I plan on using in the future so I kept it installed.
  • ua-parser PHP Library - To parse the user agent string

Install

Install Browser Filter:

$ composer require spinen/laravel-browser-filter

The package uses the auto registration feature of Laravel 5.

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

Register the middleware

The middleware needs to be registered with the Kernel to allow it to parse the request.

Register the HTTP Stack Middleware for the web group in app/Http/Kernel.php:

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

Register the Route Middlewares in app/Http/Kernel.php:

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

Build a page with a named route to redirect blocked browsers to:

    // 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.";
    }]);

Configure middleware options

Publish the package config file to config/browserfilter.php:

$ php artisan vendor:publish --provider="Spinen\BrowserFilter\FilterServiceProvider"

This file is fully documented, so please read it to know how to configure the middleware. There are 4 top level items that you can configure...

  1. type - The type of filtering strategy to apply to the stack filter
  2. rules - The array of devices/browsers/versions to allow or block for ALL http requests
  3. route - The name of the route to redirect the user to if they are using a blocked client
  4. timeout - The length of time to cache the client data, where "0" disables the cache

Using the Route middleware

The route middleware uses the same configuration file as the stack middleware, but ignores the rules.

The rules are passed in after the ':' behind the route filter that you wish to use...

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

or

    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";
        }
    ]);

The format of the filter is Device/Browser/operatorVersion|operatorVersion2;Device/Browser2/operatorVersion, so the following rule:

    $rule = [
        'Mobile' => '*',
        'Other' => [
            'Ie' => [
                '<' => '10',
                '>' => '13',
            ],
        ],
        'Tablet' => '*',
    ]

would be written as: Mobile;Other/Ie/<10|>13;Tablet.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].