5 Laravel Middleware Tricks You Probably Are Not Using
Middleware in Laravel goes well beyond authentication guards. These five techniques cover terminable middleware, priority ordering, route-level parameters, and more.
Most Laravel developers use middleware for authentication and maybe a CORS header or two, and then leave the rest of the feature set untouched. That is leaving a lot on the table. Here are five middleware patterns worth knowing. 1. Terminable Middleware — Run Code After the Response Is Sent Normal middleware runs before or after the controller, but still within the request/response cycle. Terminable middleware runs after the response has already been sent to the browser. This is ideal for expensive operations that the user should not have to wait for — logging, analytics, session writes, and cache warming. class RecordPageView implements TerminableMiddleware { public function handle(Request $request, Closure $next): Response { return $next($request); } public function terminate(Request $request, Response $response): void { // Runs after the response is sent — user never waits for this PageView::record( url: $request->fullUrl(), statusCode: $response->getStatusCode(), userId: $request->...
Middleware in Laravel goes well beyond authentication guards. These five techniques cover terminable middleware, priority ordering, route-level parameters, and more.
PHP 8.4 shipped property hooks, asymmetric visibility, and more. Here is what each feature means for your day-to-day Laravel code and how to start using them now.
These five underused Eloquent features will help you write less code, run fewer queries, and make your models a lot more pleasant to work with.
Nuno Maduro just shipped Moat, a free Rust-powered CLI that scans your GitHub account, org, or repo and gives your security posture a hard look. Here is what it checks and why you should care.