Skip to content

Commit

Permalink
Wording.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 24, 2015
1 parent 48d1ce0 commit 80a81ec
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,38 @@ As you can see, if the given `age` is less than `200`, the middleware will retur

It's best to envision middleware as a series of "layers" HTTP requests must pass through before they hit your application. Each layer can examine the request and even reject it entirely.

### *Before* vs *after* middleware
### *Before* / *After* Middleware

Whether a middleware runs *before* or *after* a request has been processed depends on how it performs its action:
Whether a middleware runs before or after a request depends on the middleware itself. This middleware would perform some task **before** the request is handled by the application:

<?php namespace App\Http\Middleware;

class BeforeMiddleware implements Middleware {

public function handle($request, Closure $next)
{
// Perform action

return $next($request);
}
}

or
However, this middleware would perform its task **after** the request is handled by the application:

<?php namespace App\Http\Middleware;

class AfterMiddleware implements Middleware {

public function handle($request, Closure $next)
{
$response = $next($request);

// Perform action

return $response;
}
}

As you can see, the before middleware operates and then passes on the request. The after middleware, on the other hand, allows the request to be processed, and then operates on it.

<a name="registering-middleware"></a>
## Registering Middleware

Expand Down

0 comments on commit 80a81ec

Please sign in to comment.