Search code examples
phplaravelmiddlewarelaravel-11

Registering Laravel Middleware without make it global


I'm new in laravel and I confused to how can I register middleware without making it global. in the documentation I only found it to be registered like this (bootstrap\app.php): bootstrap\app.php

this resulting every routes I go was applied with AdminCheck middleware. meanwhile I only want login routes to be applied. also with the laravel breeze there is 'auth' middleware but I can't find the code definition anywhere in the folder structure. can someone explain? thx


Solution

  • Route::get('/', function () {
      // ...
    })->middleware([First::class, Second::class]);
    

    Check the official doc for more information.