Middleware Has a Way Out: Laravel Middleware Beyond Auth
Most Laravel developers meet middleware through auth or a package install. Few write their own. Fewer know it can change a response on the way out, reply without reaching the controller, or wrap a queued job.
We'll look at middleware in both directions and inside queued jobs, using real cases like idempotency, caching and multi-tenancy. Learn how to keep cross-cutting concerns out of your business logic, and which pitfalls to avoid.
Middleware is a pipeline, and traffic flows both ways. Most of us only think about the trip in. But the trip back out is where a lot of the interesting work happens, and the same pattern turns up in places you might not expect.
In this talk, we'll go through middleware in both directions, see why the order you register it in matters more than you'd think, and look at what can still happen after the response has left. We'll then follow the pattern off the HTTP stack and into queued jobs, before taking a look at the machinery that powers it all.
The examples come from real production and open-source work, but the lessons apply well beyond them. Whatever your app does, there's probably logic sitting in a controller or job right now that would be happier somewhere else.
Expect practical code, a few traps that have caught us out along the way, and a quick look at how the wider PHP world tackles the same problem.