Laravel return redirect to back url with input form data

Laravel redirect back function not working. How to send form data back when validation failed. How to work laravel return redirect back() function. Example of the Redirect Back () method. Laravel return redirect to back url with input form data

Laravel return redirect back

We can send current url to previous location by return back or redirect back method.

return back();
//OR
return redirect()->back();

Laravel return redirect back with inputs details

When laravel goes to redirect back then input request data save in flash Session. We use the withInput() method for storing input data in session and printing on the previous location.

return back()->withInput();

After the user redirects back you can print input data by session, See the below example we have a name field and return it data back by validation failed.

@if (session('name'))
    <div class="alert alert-success">
        {{ session('name') }}
    </div>
@endif
php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links