我的路线定义为
Route::get('/test', 'Package\Namespace\Controllers\TestController@index')
->name('index-test')
->middleware(['Package\Namespace\Middleware\TestMiddleware']);
我想调用另一个保留语法(->middleware(...)
)的中间件。我看了at the docs,但我无法弄清楚如何使用上面的语法和命名空间中间件(我正在开发一个包)
答案 0 :(得分:2)
它的正确数组:
Route::get('/test', 'Package\Namespace\Controllers\TestController@index')
->name('index-test')
->middleware(['Package\Namespace\Middleware\TestMiddleware','Package\Namespace\Middleware\TestMiddleware2','Package\Namespace\Middleware\TestMiddleware3']);
到pass parameters to middleware:中间件参数可能是 通过分隔中间件名称定义路由时指定 和参数:。应该用多个参数分隔 逗号:
Route::get('/test', 'Package\Namespace\Controllers\TestController@index')
->name('index-test')
->middleware(['Package\Namespace\Middleware\TestMiddleware:parameter','Package\Namespace\Middleware\TestMiddleware2:parameter','Package\Namespace\Middleware\TestMiddleware3:parameter']);