我需要在Laravel 5.1中获得帮助,了解如何命名MessageBag错误,以便我可以检索特定表单的错误消息。这可以在控制器的存储方法中实现,而无需使用请求。Laravel 5.1文档
return redirect('register')
->withErrors($validator, 'login');
但我正在使用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');
}