多层Route::group,中间件失效

zh7314

centos7.9 php8 webmen 1.3.14

Route::group('/luckysheet', function () {
    Route::post('/load', [app\controller\Api\LuckysheetController::class, 'load']);
    Route::post('/updateImg', [app\controller\Api\LuckysheetController::class, 'updateImg']);
    Route::post('/loadsheet', [app\controller\Api\LuckysheetController::class, 'loadsheet']);
})->middleware([app\middleware\CrossDomain::class]);

Route::group('/luckysheet', function () {
    Route::group('/api', function () {
        Route::post('/load', [app\controller\Api\LuckysheetController::class, 'load']);
        Route::post('/updateImg', [app\controller\Api\LuckysheetController::class, 'updateImg']);
        Route::post('/loadsheet', [app\controller\Api\LuckysheetController::class, 'loadsheet']);
    });
})->middleware([app\middleware\CrossDomain::class]);

多层分组导致中间 app\middleware\CrossDomain::class 附加属性
$request->data = 'some value';

但是控制器无法获取到,

如果写在内层可以获取到

Route::group('/luckysheet', function () {
    Route::group('/api', function () {
        Route::post('/load', [app\controller\Api\LuckysheetController::class, 'load']);
        Route::post('/updateImg', [app\controller\Api\LuckysheetController::class, 'updateImg']);
        Route::post('/loadsheet', [app\controller\Api\LuckysheetController::class, 'loadsheet']);
    })->middleware([app\middleware\CrossDomain::class]);
});

这个算是bug吗?

1026 1 0
1个回答

six

手册有写,要放内层

  • 暂无评论
年代过于久远,无法发表回答
×
🔝