Performance: Registering middleware
MEDIUM IMPACT
This affects the request handling speed and response time by adding processing steps before or after the main application logic.
protected $routeMiddleware = ['check.user' => \App\Http\Middleware\CheckUser::class]; // Apply middleware only on specific routes Route::middleware(['check.user'])->group(function () { Route::get('/dashboard', function () { // Controller logic here }); });
protected $middleware = [\App\Http\Middleware\CheckUser::class];| Pattern | Middleware Runs On | Processing Overhead | Response Time Impact | Verdict |
|---|---|---|---|---|
| Global Middleware | All requests | High | Increases latency on all requests | [X] Bad |
| Route-specific Middleware | Selected routes only | Low | Minimal impact on unrelated requests | [OK] Good |