This post assumes basic familiarity with Laravel’s https://laravel.com/docs/9.x/lifecycle and https://laravel.com/docs/9.x/middleware. Before middleware can be used to authenticate users, set the app language, or limit responses based on the request.

In this post, we’ll look at a handy but less utilized type of middleware: Terminable middleware.

The illustration above, based on a graphic from https://laravelupandrunning.com/, shows where before, after, and terminable middleware are processed during the request lifecycle.

Unlike other types of middleware, terminable middleware define a terminate() method rather than handle().
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners