Jun 11, 2017
0
Level 1
redirecting withErrors not storing errors in session
I am trying to do two steps to validation. First, standard form validation that required fields are filled in. Then, I'm creating a Validator instance and adding an error, then redirecting and including withErrors().
I think I'm doing this all wrong. I'm not getting the errors in the session (I'm testing by logging session every hit to the page).
What am I doing wrong?
Log::info('session data: '.json_encode($request->session()->all()));
if(!$request->isMethod('post')) {
return view('auth.login');
} else {
$initialValidate = $this->validate($request, [
'g-recaptcha-response' => 'bail|required|captcha',
'username' => 'required|email',
'password' => 'required',
]);
$username = $request->get('username', null);
$password = $request->get('password', null);
$remember = $request->get('remember', false);
$validator = Validator::make($request->all(),[]);
try {
GlobalHelper::authenticateUser($username, $password);
} catch(ContactInvalidException $e) {
$validator->errors()->add('authentication', 'Sorry, your email address or password are incorrect. Please try again.');
} catch(ContactAuthenticationException $e) {
$validator->errors()->add('authentication', 'Sorry, your email address or password are incorrect. Please try again.');
}
if ($validator->fails()) {
redirect('user_login')
->withErrors($validator)
->withInput();
}
}
Please or to participate in this conversation.