0

When I route:list all routes in the system, I find some of the routes have Closure middleware. Although I did only assign api and auth a middlewares

api.php

Route::post('api/favorites/{post}', 'api/favorites/{post}')->middleware('auth');

Output

| Method |         URI          |        Action                 |    Middleware 
-------------------------------------------------------------------------------------
| POST   | api/favorites/{post} | \FavoritesController@favorite | api,auth,Closure 
Muaath Alhaddad
  • 341
  • 2
  • 14

1 Answers1

0

Middlewares can be set as a Closure as well. In case you need a middleware for a single usage only then you don't need to create a dedicated middleware for that. Instead, you can just add a Closure middleware in your Controller's __construct:

public function __construct(Request $request)
{
   $this->middleware(function ($request, $next) {
       //your logic
       return $next($request);
   });
}
Muaath Alhaddad
  • 341
  • 2
  • 14