How to redirect back to form with input - Laravel 5

后端 未结 9 1191
离开以前
离开以前 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());
    
    0 讨论(0)
  • 2020-12-01 03:07

    this will work definately !!!

      $v = Validator::make($request->all(),[
      'name' => ['Required','alpha']
      ]);
    
       if($v->passes()){
         print_r($request->name);
       }
       else{
         //this will return the errors & to check put "dd($errors);" in your blade(view)
         return back()->withErrors($v)->withInput();
       }
    
    0 讨论(0)
  • 2020-12-01 03:09

    You can use any of these two:

    return redirect()->back()->withInput(Input::all())->with('message', 'Some message');

    Or,

    return redirect('url_goes_here')->withInput(Input::all())->with('message', 'Some message');

    0 讨论(0)
  • 2020-12-01 03:12

    write old function on your fields value for example

    <input type="text" name="username" value="{{ old('username') }}">
    
    0 讨论(0)
  • 2020-12-01 03:13
    $request->flash('request',$request);
    
    <input type="text" class="form-control" name="name" value="{{ old('name') }}">
    

    It works for me.

    0 讨论(0)
  • 2020-12-01 03:15

    Laravel 5:

    return redirect(...)->withInput();
    

    for back only:

    return back()->withInput();
    
    0 讨论(0)
提交回复
热议问题