如何通过输入重新导向形式 - Laravel 5 [英] How to redirect back to form with input - Laravel 5

查看:227
本文介绍了如何通过输入重新导向形式 - Laravel 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的表单动作引发异常,我该如何重定向回到我的表单页面,给定的 POST params?



return Redirect :: back() - > withInput(Input :: all());

如果您使用表单请求验证,这正是Laravel如何将错误和给定输入重定向回来。



摘自 \Illuminate\Foundation\Validation\ValidatesRequests


  return redirect() - > to($ this-> getRedirectUrl())
- > withInput($ request-> input())
- > withErrors($ errors,$ this-> errorBag());



How do I redirect back to my form page, with the given POST params, if my form action throws an exception?

解决方案

You can use the following:

return Redirect::back()->withInput(Input::all());

If you're using Form Request Validation, this is exactly how Laravel will redirect you back with errors and the given input.

Excerpt from \Illuminate\Foundation\Validation\ValidatesRequests:

return redirect()->to($this->getRedirectUrl())
                    ->withInput($request->input())
                    ->withErrors($errors, $this->errorBag());

这篇关于如何通过输入重新导向形式 - Laravel 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆