我可以将路由分配给多个中间件组吗?:
Route::group(['middleware' => 'auth:api'], function() {
Route::any('/lookup', 'LookupController@lookup')->name('lookup');
});
Route::group(['middleware' => 'custom'], function() {
Route::any('/lookup', 'LookupController@lookup')->name('lookup');
});
但是我不想将两个中间件组合在一个组中:
Route::group(['middleware' => ['auth:api', 'custom'], function() {
Route::any('/lookup', 'LookupController@lookup')->name('lookup');
});
编辑:
Route::group(['middleware' => ['auth:api']], function () {
Route::group(['middleware' => ['custom']], function () {
Route::any('/lookup', 'LookupController@lookup')->name('lookup');
});
});
对我的案例不起作用,因为我希望第一组中的某些路由不在第二组中,反之亦然。
可以使用变量吗?
$lookupRoute = Route::any('/lookup', 'LookupController@lookup')->name('lookup');
Route::group(['middleware' => 'auth:api'], function() {
??? $lookupRoute ???
});
Route::group(['middleware' => 'custom'], function() {
??? $lookupRoute ???
});