Performance: Middleware groups
Middleware groups affect the request handling speed and server response time by controlling how many middleware run per request.
Route::middleware(['web', 'auth'])->group(function () { Route::get('/dashboard', function () { return view('dashboard'); }); });
Route::get('/dashboard', function () { return view('dashboard'); })->middleware(['auth', 'verified', 'throttle:60,1', 'customMiddleware']);
| Pattern | Middleware Executions | Server Response Time | User Interaction Delay | Verdict |
|---|---|---|---|---|
| Individual middleware per route | Multiple per route | Higher due to repeated checks | Increased INP | [X] Bad |
| Middleware groups for routes | Single group execution | Lower due to bundling | Reduced INP | [OK] Good |
app/Http/Kernel.php.protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
];Kernel.php but it does not run on routes using that group. What is a likely cause?admin that includes the auth middleware and a custom CheckAdmin middleware. How should you define it in Kernel.php?Pass the test and this pattern moves unknown