2016-02-05 27 views

回答

0

我不太清楚你的框架外的意思,但它幾乎可以歸結爲:

// Get your Illuminate\Routing\Router from somewhere. 
// This could either be from the container instance or 
// an instance you instantiated yourself somewhere 
$router = new Illuminate\Routing\Router(.... 
// or in case you plan on doing this in a service provider for example 
$router = $this->app['router']; 

// Now you add your middleware using the following syntax 
$router->middleware('name', My\Middleware::class); 

// It's also possible to add a middleware group 
$router->middlewareGroup('group_name', [ 
    'name', 
    My\Other\Middleware::class 
]); 

// It's also possible to do this using the Laravel Facade's 
Route::middleware(... 
Route::middlewareGroup(... 
+0

是的,這就是我一直在尋找的東西。謝謝!順便說一下,我還發現,在將中間件分配給路由時,我可以使用該類的全名,即Route :: group(['middleware'=> \ My \ Middleware :: class],function(){。 ..'。在整個文檔中別名的用法使我困惑。 – Okneloper

+0

太棒了,不知道那個!:) –