Middleware provide a convenient mechanism for inspecting and filtering HTTP requests entering an application; Laravel includes middleware for authentication and CSRF protection. The authentication middleware redirects unauthenticated users to the login screen but allows authenticated requests to proceed further into the application. Create middleware with the make:middleware Artisan command, which places the class in app/Http/Middleware. Each middleware defines a handle method receiving a Request and a Closure and returning a Response. The docs' EnsureTokenIsValid example allows access to the route only if the supplied token input matches 'my-secret-token'; otherwise it redirects to /home, while a match returns $next($request) to pass the request further. Middleware can perform tasks besides authentication, such as logging all incoming requests. Scope: Laravel. Reviewed October 4, 2026.
Middleware
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- laravel.com
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.