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());
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();
}
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');
write old function on your fields value for example
<input type="text" name="username" value="{{ old('username') }}">
$request->flash('request',$request);
<input type="text" class="form-control" name="name" value="{{ old('name') }}">
It works for me.
Laravel 5:
return redirect(...)->withInput();
for back only:
return back()->withInput();