Skip to content

Commit 4144497

Browse files
committed
Document sorting middleware
Apparently this wasn't documented yet: laravel/framework#24854
1 parent 1b282ce commit 4144497

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

middleware.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Global Middleware](#global-middleware)
77
- [Assigning Middleware To Routes](#assigning-middleware-to-routes)
88
- [Middleware Groups](#middleware-groups)
9+
- [Sorting Middleware](sorting-middleware)
910
- [Middleware Parameters](#middleware-parameters)
1011
- [Terminable Middleware](#terminable-middleware)
1112

@@ -185,6 +186,27 @@ Middleware groups may be assigned to routes and controller actions using the sam
185186

186187
> {tip} Out of the box, the `web` middleware group is automatically applied to your `routes/web.php` file by the `RouteServiceProvider`.
187188
189+
<a name="sorting-middleware"></a>
190+
### Sorting Middleware
191+
192+
In some cases you'd want to run your middleware in a specific order. You can achieve this by ordering the middleware with the `$middlewarePriority` property of your HTTP kernel. This doesn't includes global middleware which is always run before other middlewares.
193+
194+
/**
195+
* The priority-sorted list of middleware.
196+
*
197+
* This forces non-global middleware to always be in the given order.
198+
*
199+
* @var array
200+
*/
201+
protected $middlewarePriority = [
202+
\Illuminate\Session\Middleware\StartSession::class,
203+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
204+
\App\Http\Middleware\Authenticate::class,
205+
\Illuminate\Session\Middleware\AuthenticateSession::class,
206+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
207+
\Illuminate\Auth\Middleware\Authorize::class,
208+
];
209+
188210
<a name="middleware-parameters"></a>
189211
## Middleware Parameters
190212

0 commit comments

Comments
 (0)