Line up the middleware queue in the right order: 5 levels of CORS, throttle, auth and cache in the Laravel request lifecycle.
Tonight Mr. Slamet, head of the village watch, marries off his daughter in the marquee in front of his house in Kenanga Lane. His invitation site is built with Laravel, and volunteers guard the posts along the road from the lane gate to the marquee. Tap a guard onto a post, then send the guests through. A middleware is a guard between the request and the controller. Each guard takes the request in handle($request, $next): it may answer it itself, or call $next($request) so the request goes on to the next guard and in the end to the controller. The controller's answer then goes home past the same guards in reverse order. Here each guard is a volunteer at a post, each request a guest, and the controller the marquee at the end of the road.
Laravel runs middleware from three places. The global list (bootstrap/app.php, $middleware->use([...])) is met by every request, before the router looks for its route. Once a route is found, its group's middleware (web or api) and the route's own are merged, then sorted by the router by Laravel's priority list. So a request always passes the gate first, then the fence, then the door.
The controller's answer goes home past the same guards in reverse order, and some guards do their work on that way home: adding a header, stamping, writing down. A guard that turns a guest away sends its answer from its own post, so the guards behind it never see that answer.
A middleware may have a terminate($request, $response) method. The HTTP kernel calls it after the answer has been sent to the browser, so slow work such as writing a log keeps no guest waiting. The kernel makes a fresh instance for terminate(), so data from handle() is left on the $request, not on $this.