LARAVEL 在视图中获取 withErrors 的结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22244442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
LARAVEL get result of withErrors in view
提问by DolDurma
in controller i'm using:
在我使用的控制器中:
if ($validator->fails())
{
return Redirect::to('/admin/profile')
->withErrors($validator)
->withInput();
}
how to get result of withErrors in view ?
如何在视图中获得 withErrors 的结果?
{{ $errors->all() }}
回答by tliokos
If you want to show all errors in one place you can use
如果您想在一个地方显示所有错误,您可以使用
@foreach ($errors->all() as $error)
<div>{{ $error }}</div>
@endforeach
If you want to show each field's errors e.g. bellow the field you can use (e.g. for email)
如果您想显示每个字段的错误,例如在您可以使用的字段下方(例如用于电子邮件)
{{ $errors->first('email') }}
we use first() in order to show only one error each time for each field.
我们使用 first() 是为了每个字段每次只显示一个错误。