Laravel 5.1 Multiple forms on the same page name Message bag

I need help in Laravel 5.1 on how to name MessageBag errors, letting me get error messages for a specific form.

This can be achieved in the controller storage method without using a request.

Laravel 5.1 docs

return redirect('register')
            ->withErrors($validator, 'login');

But I use RegisterRequest, so I do not need to check any data 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');
    }
+4
source share
1 answer

I had the same problem, and when I looked in the FormRequest class, I found that a property exists protected $errorBag = 'default'.

, , ,
protected $errorBag = 'login';

, :

$errors->login->has('email')

+6

All Articles