LARAVEL get result of withErrors in view

岁酱吖の 提交于 2019-12-10 22:03:44

问题


in controller i'm using:

if ($validator->fails())
{
   return Redirect::to('/admin/profile')
    ->withErrors($validator)
    ->withInput();
}

how to get result of withErrors in view ?

{{ $errors->all() }}

回答1:


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.



来源:https://stackoverflow.com/questions/22244442/laravel-get-result-of-witherrors-in-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!