laravel 5.3 Illuminate \ Routing \ Router :: middleware()缺少参数2

时间:2018-12-30 08:07:39

标签: laravel-5

Illuminate \ Routing \ Router :: middleware()缺少参数2

api.php

Route::middleware('auth:api')->get('/user', function (Request $request) { return $request->user(); });

RouteServiceProvider.php

protected function mapApiRoutes()
{
Route::group([
    'middleware' => ['api', 'auth:api'],
    'namespace' => $this->namespace,
    'prefix' => 'api',
], function ($router) {
    require base_path('routes/api.php');
});
}

1 个答案:

答案 0 :(得分:0)

我有同样的问题。问题是直到版本5.4,您才能调用Route::middleware('auth:api')

在5.3版中,它必须称为Route::group(['middleware' => 'auth:api'], function() { ... })