intermediateLaravel
What is the difference between global and route middleware?
Answer
Clear, interview-ready explanation
Global middleware runs for every HTTP request handled by the application. It is appropriate for behavior that must be applied consistently, such as trimming input strings, converting empty strings to null, or handling proxies.
Route middleware runs only on routes or route groups to which it is assigned. It is suited to concerns such as authentication, permissions, rate limiting, or an admin-only check. Route middleware keeps special requirements local to the affected endpoints, while global middleware should be used sparingly because it affects the entire application.