我在Laravel 5.1中需要有关如何命名MessageBag错误的帮助,允许我检索特定表单的错误消息.
这可以在没有使用请求的控制器的存储方法中实现.
return redirect('register')
->withErrors($validator, 'login');
Run Code Online (Sandbox Code Playgroud)
但是我正在使用RegistrationRequest,因此我不需要验证控制器内的任何输入,我只需要在请求中设置我的规则.
我尝试将这行代码添加到我的请求中
/**
* 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');
}
Run Code Online (Sandbox Code Playgroud)