$user = User::where('email', $request->email)->first();
if (!$user || !Hash::check($request->password, $user->password)) {
return response([
'message' => ['Credenitials do no match']],404);
}
有人可以让我理解if块吗?
答案 0 :(得分:1)
首先,它尝试通过http请求中传递的电子邮件查找用户:
$user = User::where('email', $request->email)->first();
然后,它检查用户是否存在,并且数据库中存储的密码的哈希值是否与请求中传递的(哈希值)密码匹配:
if (!$user || !Hash::check($request->password, $user->password)) {
如果没有,则返回带有404状态和消息的响应:
'message' => ['Credenitials do no match']],404);
如果密码匹配,则代码继续。