未验证电子邮件时处理电子邮件验证响应

时间:2019-08-21 13:29:19

标签: php laravel laravel-5.8

在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

1返回我想要的消息

Route::middleware('auth:api')->group(function () {

    Route::get('products/{product}', 'ProductController@show')->middleware('verified'); // #1

    Route::get('user', 'UserController@profile')->middleware('verified'); // #2

}

2返回类似这样的内容

{
    "responseMessage": "Your email address is not verified.",
    "responseStatus": 400
}

我做错了什么?

0 个答案:

没有答案