在laravel 5.8 API应用程序中,我想传递用户未验证其电子邮件地址时返回的响应消息。为此,我在render
的{{1}}方法中添加了以下代码,如下所示:
Handle.php
然后我将中间件添加到if (
!$request->user() || ($request->user() instanceof MustVerifyEmail &&
!$request->user()->hasVerifiedEmail())
) {
return response()->json([
'responseMessage' => 'Your email address is not verified.',
'responseStatus' => 400
]);
}
的以下路由中
api.php
Route::middleware('auth:api')->group(function () {
Route::get('products/{product}', 'ProductController@show')->middleware('verified'); // #1
Route::get('user', 'UserController@profile')->middleware('verified'); // #2
}
{
"responseMessage": "Your email address is not verified.",
"responseStatus": 400
}
我做错了什么?