How to redirect back to form with input - Laravel 5

后端 未结 9 1190
离开以前
离开以前 2020-12-01 02:53

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

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 03:03

    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());
    

提交回复
热议问题