I need help in Laravel 5.1 on how to name the MessageBag errors, allowing me to retrieve the error messages for a specific form.
This can be achieve in the store method of a controller without the using request.
Laravel 5.1 docs
return redirect('register')
->withErrors($validator, 'login');
But I am using a RegistrationRequest so I do not need to validate any input inside my controller I just need to set my rules in the request.
I tried this line of codes added to my request
/**
* Format the errors from the given Validator instance.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return array
*/
protected function formatErrors(Validator $validator)
{
return $validator->errors()->getMessages('registration');
}
I had the same problem, and when I looked in the FormRequest class, I found there was a property protected $errorBag = 'default'
.
So, by overriding this propery in your request class, e.g.protected $errorBag = 'login';
you can scope the errors from that request and then access them in your view like so:
$errors->login->has('email')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With