PHPackages                             slushie/laravel-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. slushie/laravel-middleware

ActiveLibrary[Framework](/categories/framework)

slushie/laravel-middleware
==========================

Laravel 4 Middleware Loader

1754PHP

Since Nov 22Pushed 12y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

middleware
==========

[](#middleware)

Laravel 4 Middleware Configuration Loader

This package provides a simple configuration point where you can add middleware to the Laravel 4 request processing pipeline.

It works by adding callbacks to the `App::before()` and `App::after()`application-level events. Classes are registered in the `app.middleware`configuration key array (that is, `middleware` is an array defined in the `app/config/app.php` file).

How To Use
----------

[](#how-to-use)

First, create a class that implements at least one of `Slushie\Middleware\BeforeInterface` or `Slushie\Middleware\AfterInterface`. Then implement the `onBefore($request)` and `onAfter($request, $response)`methods. You can return a non-`null` value from an `onBefore` handler to halt request processing, just like with Laravel's `App::before()`. Return values for `onAfter()` are ignored.

```
class RedirectBeforeMiddleware implements BeforeInterface {
  public function onBefore($request) {
    if ($request->query('mobile') == 'redirect') {
      return Redirect::to('/mobile');
    }
  }
}

class TimingMiddleware implements BeforeInterface, AfterInterface {
  public function onBefore($request) {
    $this->start_time = time();
  }

  public function onAfter($request, $response) {
    $duration = time() - $this->start_time;
    Log::info("Processing {$request->url()} took {$duration} sec");
  }
}

```

Next, configure your application to load the `MiddlewareServiceProvider`as well as adding your own middleware classes to the `middleware` configuration key.

For example, your `app/config/app.php` file might include:

```
'providers' => array(
  // .. snip ..

  'Slushie\Middleware\MiddlewareServiceProvider'
),

'middleware' => array(
  'RedirectBeforeMiddleware',
  'TimingMiddleware'
)

```

How It Works
------------

[](#how-it-works)

The `MiddlewareServiceProvider` creates objects from all classes in the `app.middleware` array using the IoC container. Any class that implements `BeforeInterface` is used as `before` middleware, and any class that implements `AfterInterface` is used as an `after` middleware. Of course, a class can implement both interfaces to be used at both control points.

Rationale
---------

[](#rationale)

Although Laravel provides a simple method to apply middleware in each application via the `App::before()` and `App::after()` methods, this approach does not lend itself to simple configuration.

This means that packages that need to apply middleware to the requests must do so in their service provider instances, which enforces this behaviour in user applications.

This package provides a means for application developers and administrators to selectively enable and disable middleware without resorting to editing application code (such as `app/filters.php`).

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/49fb37c7c9cf1d7c2321fd555229abd5913fbe90c1ab3ea6cc83a3a5a21541fa?d=identicon)[slushie](/maintainers/slushie)

---

Top Contributors

[![slushie](https://avatars.githubusercontent.com/u/35512?v=4)](https://github.com/slushie "slushie (9 commits)")

### Embed Badge

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

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

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[spiral/roadrunner

RoadRunner: High-performance PHP application server and process manager written in Go and powered with plugins

8.4k12.2M84](/packages/spiral-roadrunner)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)

PHPackages © 2026

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