我正在使用該attempt()方法對用戶進行身份驗證:
if (!Auth::attempt($request->only('phone', 'password'))) {
return response()->json([
'message' => 'Invalid login details'
], 401);
}
問題是我需要檢查status用戶表中的欄位是否為真。怎么做?
我閱讀了更多檔案并發現了這一點:
$credentials = ['phone' => $request->phone, 'password' => $request->password, 'status' => 1];
if (!Auth::attempt($request->only($credentials))) {}
uj5u.com熱心網友回復:
您也可以采用這種方法:
if (Auth::attempt($request->only('phone', 'password'))) {
//logged in but account inactive
if(!auth()->user()->status){
return response()->json([
'message' => 'Account Inactive'
],403);
}
//redirect to dashboard
//user logged in
return response()->json([
//data you want to send
],200);
}
//login failed
return response()->json([
'message' => 'Invalid login details'
], 401);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/514630.html
標籤:拉拉维尔
上一篇:Laravel遷移失敗
