PHPackages                             barryvdh/laravel-stack-middleware - 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. [Framework](/categories/framework)
4. /
5. barryvdh/laravel-stack-middleware

ActiveLibrary[Framework](/categories/framework)

barryvdh/laravel-stack-middleware
=================================

Stack Middleware for Laravel

v1.4.2(1y ago)43421.7k↓45.2%7[1 PRs](https://github.com/barryvdh/laravel-stack-middleware/pulls)5MITPHPPHP ^8.1

Since Feb 17Pushed 1y ago3 watchersCompare

[ Source](https://github.com/barryvdh/laravel-stack-middleware)[ Packagist](https://packagist.org/packages/barryvdh/laravel-stack-middleware)[ RSS](/packages/barryvdh-laravel-stack-middleware/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (3)Versions (26)Used By (5)

Stack Middleware for Laravel
----------------------------

[](#stack-middleware-for-laravel)

[![Tests](https://github.com/barryvdh/laravel-stack-middleware/workflows/Tests/badge.svg)](https://github.com/barryvdh/laravel-stack-middleware/actions)[![Packagist License](https://camo.githubusercontent.com/3b3fa8b4b933bc1ae9a7faf24e6ea3f1c1573b7c4c84247f3e8003ca93ba1581/68747470733a2f2f706f7365722e707567782e6f72672f62617272797664682f6c61726176656c2d737461636b2d6d6964646c65776172652f6c6963656e73652e706e67)](http://choosealicense.com/licenses/mit/)[![Latest Stable Version](https://camo.githubusercontent.com/fe074813cbccfe19ba46bf3bbcb665209bccd56729202ac37d0cc568459f3ae1/68747470733a2f2f706f7365722e707567782e6f72672f62617272797664682f6c61726176656c2d737461636b2d6d6964646c65776172652f76657273696f6e2e706e67)](https://packagist.org/packages/barryvdh/laravel-stack-middleware)[![Total Downloads](https://camo.githubusercontent.com/9457ccefd5c7537a2f1d1c491419f4576ba9233235476e9f0b23574d7700b490/68747470733a2f2f706f7365722e707567782e6f72672f62617272797664682f6c61726176656c2d737461636b2d6d6964646c65776172652f642f746f74616c2e706e67)](https://packagist.org/packages/barryvdh/laravel-stack-middleware)[![Fruitcake](https://camo.githubusercontent.com/28d7584b52e33d7b4ffb6b1bef8b89b6e598adb45c8c0d5f80349c1c304f385e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f776572656425323042792d467275697463616b652d6232626333352e737667)](https://fruitcake.nl/)

Laravel 4 used [HttpKernelInterface Middlewares](http://stackphp.com/middlewares/) for its Middleware, but Laravel 5 uses a new way. This package provides a way to wrap StackPHP Middleware so it can be used with Laravel 5

First, require this package in your composer file

```
composer require barryvdh/laravel-stack-middleware

```

After updating, add the ServiceProvider to the array of providers in config/app.php

```
Barryvdh\StackMiddleware\ServiceProvider::class,

```

### Usage

[](#usage)

A Stack Middleware usually needs a Kernel. We can't use the real Kernel, so this package provides a one. You can use the `bind` method to wrap a Stack (HttpKernelInterface) middleware and register it in the App container. You can access the StackMiddleware class under the `stack` key in the Container, or with the Facade (`Barryvdh\StackMiddleware\Facade`). It can also be typehinted directly, eg. on the `boot()` method of a ServiceProvider.

The first argument is the new Middleware name. The second is either:

- A closure, which gets the new Kernel as first parameter.
- The name of the class to resolve with the App container. Parameters can be provided as an array as the third argument. The Kernel is prepended to that array, so it's always injected as first argument.

```
app('stack')->bind('AddRobotsHeaders', 'League\StackRobots\Robots', ['env' => 'production', 'envVar' => 'APP_ENV']);
```

```
use League\StackRobots\Robots;
use Barryvdh\StackMiddleware\StackMiddleware;

public function boot(StackMiddleware $stack) {
    $stack->bind('AddRobotsHeaders', function($kernel) {
        return new Robots($kernel, 'production', 'APP_ENV');
    });
}
```

Both examples have the same result, you can now add `AddRobotsHeaders` to the $middleware list in Kernel.php

If you want to use the Facade, you can add that to your config/app.php. You can then use `Stack::bind(...)` instead.

```
    'Stack' => 'Barryvdh\StackMiddleware\Facade',
```

### Examples &amp; Implementations

[](#examples--implementations)

- [StackRobots](https://github.com/thephpleague/stack-robots): Just require and use examples from above.
- [HttpCache](http://symfony.com/doc/current/book/http_cache.html):

### More information

[](#more-information)

For more information, read the [StackPHP website](http://stackphp.com/).

### License

[](#license)

[MIT](LICENSE)

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance41

Moderate activity, may be stable

Popularity47

Moderate usage in the ecosystem

Community24

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71% 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 ~166 days

Recently: every ~187 days

Total

23

Last Release

497d ago

Major Versions

v0.2.4 → v1.0.02016-08-25

PHP version history (6 changes)v0.1.0PHP &gt;=5.4.0

v0.2.3PHP &gt;=5.5

v1.2.4PHP &gt;=7

v1.3.0PHP &gt;=7.2

v1.3.1PHP ^8

v1.4.2PHP ^8.1

### Community

Maintainers

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

---

Top Contributors

[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (49 commits)")[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (12 commits)")[![tortuetorche](https://avatars.githubusercontent.com/u/5038872?v=4)](https://github.com/tortuetorche "tortuetorche (4 commits)")[![okaufmann](https://avatars.githubusercontent.com/u/4414498?v=4)](https://github.com/okaufmann "okaufmann (2 commits)")[![jshah4517](https://avatars.githubusercontent.com/u/602425?v=4)](https://github.com/jshah4517 "jshah4517 (1 commits)")[![Omranic](https://avatars.githubusercontent.com/u/406705?v=4)](https://github.com/Omranic "Omranic (1 commits)")

---

Tags

middlewarelaravelstackStackPHP

### Embed Badge

![Health badge](/badges/barryvdh-laravel-stack-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/barryvdh-laravel-stack-middleware/health.svg)](https://phpackages.com/packages/barryvdh-laravel-stack-middleware)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[livewire/livewire

A front-end framework for Laravel.

23.6k89.0M2.7k](/packages/livewire-livewire)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k95.4M306](/packages/laravel-horizon)[laravel/sail

Docker files for running a basic Laravel application.

1.9k205.7M1.3k](/packages/laravel-sail)[illuminate/routing

The Illuminate Routing package.

1419.2M3.0k](/packages/illuminate-routing)

PHPackages © 2026

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