Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect back to form with input - Laravel 5

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

like image 966
Danny Kopping Avatar asked Jun 26 '15 20:06

Danny Kopping


People also ask

How do I redirect back in laravel?

If you just want to redirect a user back to the previous page (the most common example - is to redirect back to the form page after data validation failed), you can use this: return redirect()->back();

How do I redirect back to original URL after successful login in laravel?

You may use Redirect::intended function. It will redirect the user to the URL they were trying to access before being caught by the authenticaton filter.

How do I redirect one page to another in laravel?

Redirect to a specific page in Laravel using ajax - Stack In order to redirect everything on web routes, you can add the following piece of code in your app's route/web. php file Route::any( '{catchall}', function(){ // return redirect( 'https://digitizor.com' ) // OR, Do something here })->where( 'catchall', '.


2 Answers

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()); 
like image 128
Danny Kopping Avatar answered Sep 19 '22 09:09

Danny Kopping


write old function on your fields value for example

<input type="text" name="username" value="{{ old('username') }}"> 
like image 35
Vishal Rambhiya Avatar answered Sep 22 '22 09:09

Vishal Rambhiya