How to do Return Redirect Back to the page in Laravel

In Laravel, we have an option to return back to the page after we run a POST or GET request and that’s very simple to do.

in this post, i will show you how to simply do that also i will show you how to send a response with it.

So In the controller, you have to add the return code like this

return redirect()->back();

so We are using the back() function it will return back to where we are.

so what if you want to send a response with that like a success or error message

return redirect()->back()->with('success', 'Post Created Successfully');

Like this.

So in the view part, you can display the success message as an alert, Use this code as a template

@if (\Session::has('success'))
 	<div class="alert alert-success" role="alert">
             {!! \Session::get('success') !!}
        </div>
@endif

 

That’s all. Now you got an idea right. Hope this helps

 

 

Ajith Jojo Joseph

Hire Me for Freelancing $30/Hour ,
Contact via email : [email protected]

Share with your friends:

Comments are closed.

How To Generate A PDF from HTML in Laravel 11

Hello , I was trying to generate a PDF payment receipt for my SAAS application and when i search for […]

June 22, 2024

How to create Laravel Flash Messages

Laravel flash messages are a convenient way to display one-time notifications to the user after a form submission or other […]

December 22, 2022

How to make Custom Artisan Command in Laravel

Custom Artisan commands are a useful feature of Laravel that allow you to define your own command-line commands for tasks […]

December 22, 2022

Tips for Laravel migrations

Laravel migrations are a powerful tool for managing and modifying your database schema in a structured and organized way. Here […]

December 22, 2022

Digital Marketing Toolkit

Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits

Get Free Access Now