我在Laravel 5.4中創建了一個登錄函數,並且當密碼不正確時,我想在視圖中顯示錯誤消息。此外,我還有一個自定義消息用於帳戶審批,因此對我來說有點困難。同時我把這些信息放在一起,但不是很方便用戶。我怎樣才能將它們分開?Laravel「密碼錯誤」錯誤信息
這是我的控制器:
public function login(Request $request)
{
// validate the form data
$this->validate($request, [
'email' => 'required|email|exists:users,email',
'password' => 'required|min:6'
]);
// attempt to log
if (Auth::attempt(['approve' => '1', 'email' => $request->email, 'password' => $request->password ], $request->remember)) {
// if successful -> redirect forward
return redirect()->intended(route('user.overview'));
}
// if unsuccessful -> redirect back
return redirect()->back()->withInput($request->only('email', 'remember'))->withErrors([
'approve' => 'Wrong password or this account not approved yet.',
]);
}
至於結果,我想有兩個單獨的電文代替Wrong password or this account not approved yet
:
如果密碼是錯誤的顯示:Password is wrong
如果賬戶沒有批准顯示:This account not approved yet
你可以使用這樣的:'\會議::閃存(「錯誤」,「密碼錯誤或此帳戶未獲批准尚未」); return redirect() - > back() - > withInput() - > withErrors($ errors);'然後將會話消息打印在刀片文件中! –