PHPackages                             spinen/laravel-browser-filter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. spinen/laravel-browser-filter

ActiveLibrary[HTTP &amp; Networking](/categories/http)

spinen/laravel-browser-filter
=============================

Filters http requests based on browser type.

3.2.0(2y ago)2146.3k↑55%2[2 PRs](https://github.com/spinen/laravel-browser-filter/pulls)MITPHPPHP &gt;=8.1

Since Aug 16Pushed 2y ago7 watchersCompare

[ Source](https://github.com/spinen/laravel-browser-filter)[ Packagist](https://packagist.org/packages/spinen/laravel-browser-filter)[ RSS](/packages/spinen-laravel-browser-filter/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (35)Used By (0)

SPINEN's Laravel Browser Filter
===============================

[](#spinens-laravel-browser-filter)

[![Latest Stable Version](https://camo.githubusercontent.com/6a384d6485a7bc031b39093499f13e8facf3f834c2beae3d772b1cec79264bf8/68747470733a2f2f706f7365722e707567782e6f72672f7370696e656e2f6c61726176656c2d62726f777365722d66696c7465722f762f737461626c65)](https://packagist.org/packages/spinen/laravel-browser-filter)[![Latest Unstable Version](https://camo.githubusercontent.com/1be45dfc59060e600071c68cff871ee7137e8dca27a1c1c51ae5fff64152c9fd/68747470733a2f2f706f7365722e707567782e6f72672f7370696e656e2f6c61726176656c2d62726f777365722d66696c7465722f762f756e737461626c65)](https://packagist.org/packages/spinen/laravel-browser-filter)[![Total Downloads](https://camo.githubusercontent.com/c25c5759b3cb4987695d312515409b6a80e12dff8e3001c080c096ebb620c882/68747470733a2f2f706f7365722e707567782e6f72672f7370696e656e2f6c61726176656c2d62726f777365722d66696c7465722f646f776e6c6f616473)](https://packagist.org/packages/spinen/laravel-browser-filter)[![License](https://camo.githubusercontent.com/dc49353f12c4f18f3b74c7d32b97ec086182ebbbf6b09e6da3f62edef371e56b/68747470733a2f2f706f7365722e707567782e6f72672f7370696e656e2f6c61726176656c2d62726f777365722d66696c7465722f6c6963656e7365)](https://packagist.org/packages/spinen/laravel-browser-filter)

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
------------

[](#build-status)

BranchStatusCoverageCode QualityDevelop[![Build Status](https://github.com/spinen/laravel-browser-filter/workflows/CI/badge.svg?branch=develop)](https://github.com/spinen/laravel-browser-filter/workflows/CI/badge.svg?branch=develop)[![Code Coverage](https://camo.githubusercontent.com/b3b44443e777af58f4a58ef9a5d784ee22bd4f6d6635275c5c844e038213e3d2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7370696e656e2f6c61726176656c2d62726f777365722d66696c7465722f6261646765732f636f7665726167652e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/spinen/laravel-browser-filter/?branch=develop)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/fac4eba54a1da86d827b57f0603939c16759487266727d1650227999b5554a25/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7370696e656e2f6c61726176656c2d62726f777365722d66696c7465722f6261646765732f7175616c6974792d73636f72652e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/spinen/laravel-browser-filter/?branch=develop)Master[![Build Status](https://github.com/spinen/laravel-browser-filter/workflows/CI/badge.svg?branch=master)](https://github.com/spinen/laravel-browser-filter/workflows/CI/badge.svg?branch=master)[![Code Coverage](https://camo.githubusercontent.com/b3b44443e777af58f4a58ef9a5d784ee22bd4f6d6635275c5c844e038213e3d2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7370696e656e2f6c61726176656c2d62726f777365722d66696c7465722f6261646765732f636f7665726167652e706e673f623d646576656c6f70)](https://scrutinizer-ci.com/g/spinen/laravel-browser-filter/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b54b1e91ef95231ec9733f4a6859f7b57e0e7a6b8df9b761e01c506947a5261d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7370696e656e2f6c61726176656c2d62726f777365722d66696c7465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/spinen/laravel-browser-filter/?branch=master)Prerequisites
-------------

[](#prerequisites)

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

[](#note-if-you-need-to-use-php-72-or-laravel-52-please-stay-with-version-1x)

As side from Laravel &gt;= 5.5, there are 2 packages that are required:

- [mobiledetect](https://github.com/serbanghita/Mobile-Detect) - 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](https://github.com/ua-parser/uap-php) - To parse the user agent string

Install
-------

[](#install)

Install Browser Filter:

```
$ composer require spinen/laravel-browser-filter
```

The package uses the [auto registration feature](https://laravel.com/docs/5.8/packages#package-discovery) of Laravel 5.

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

Register the middleware
-----------------------

[](#register-the-middleware)

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

### Laravel 11 &amp; newer

[](#laravel-11--newer)

Register the HTTP Stack Middleware for the web group in `bootstrap/app.php`:

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

Register the Route Middlewares in `bootstrap/app.php`:

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

### Before Laravel 11

[](#before-laravel-11)

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,
```

### Page to show if blocked

[](#page-to-show-if-blocked)

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
----------------------------

[](#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
--------------------------

[](#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' => [
                '' => '13',
            ],
        ],
        'Tablet' => '*',
    ]
```

would be written as: `Mobile;Other/Ie/13;Tablet`.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 84.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~117 days

Recently: every ~359 days

Total

28

Last Release

771d ago

Major Versions

0.8.0 → 1.0.02018-03-25

1.1.0 → 2.0.02019-02-14

2.3.2 → 3.0.02022-12-01

PHP version history (5 changes)0.1.0PHP &gt;=5.5.0

1.0.1PHP &gt;=5.5.9

2.0.0PHP &gt;=7.2

3.0.0PHP &gt;=8.0.2

3.1.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a082f934783fa6f391c37fc7e7ca71f84e17219471cadd17a8b8b85b42c2c9c1?d=identicon)[david.mathews](/maintainers/david.mathews)

![](https://www.gravatar.com/avatar/782b3ad6f100c625875d6a8f00222d0e08e0c6f0956ef757e43a38441594c013?d=identicon)[jimmypuckett](/maintainers/jimmypuckett)

![](https://www.gravatar.com/avatar/a03d6c15997b49e0fa73b6e61f6c4fbc833f1f0d2476984fe88bb38a8b866c2d?d=identicon)[ssfinney](/maintainers/ssfinney)

---

Top Contributors

[![jimmypuckett](https://avatars.githubusercontent.com/u/3220069?v=4)](https://github.com/jimmypuckett "jimmypuckett (321 commits)")[![ssfinney](https://avatars.githubusercontent.com/u/1596394?v=4)](https://github.com/ssfinney "ssfinney (58 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

browser-hawkingfilter-routeslaravellaravel-5-packagelaravel-middlewareroute-middlewarespinenmiddlewarelaravelspinenbrowser hawk

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/spinen-laravel-browser-filter/health.svg)

```
[![Health](https://phpackages.com/badges/spinen-laravel-browser-filter/health.svg)](https://phpackages.com/packages/spinen-laravel-browser-filter)
```

###  Alternatives

[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[omniphx/forrest

A Laravel library for Salesforce

2724.4M8](/packages/omniphx-forrest)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[matthewbdaly/laravel-etag-middleware

A Laravel middleware for adding ETags to HTTP requests to improve response times

64326.0k2](/packages/matthewbdaly-laravel-etag-middleware)[tomschlick/request-migrations

HTTP Request Migrations

1844.5k](/packages/tomschlick-request-migrations)[dragon-code/laravel-http-logger

Logging incoming HTTP requests

319.8k3](/packages/dragon-code-laravel-http-logger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
