If you have a middleware
, and you want to use it in a specific route
, you can pass it directly into the route without register it in the kernel file.
1Route::get('posts', PostController::class)->middleware(['auth', CustomMiddleware::class]);
You can do the same on the controller also
1class PostController extends Controller2{3 public function __construct()4 {5 $this->middleware(['auth', CustomMiddleware::class]);6 }7}
Happy Coding!