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

 

 

Post Your Questions on our forum

Post a question on Forum

Ajith Jojo Joseph

Self taught, dedicated young entrepreneur with many licensed products under his sleeve. Passionate about technology, business and excellence in general.

Share with your friends:

Comments are closed.

How to integrate Paypal API in Laravel

Are you looking to integrate Paypal API in your Laravel project for seamless payment processing? Look no further! In this […]

April 3, 2024

How to integrate Razorpay API in Laravel

Integrating payment gateways into web applications has become an essential part of e-commerce websites. In this tutorial, we will discuss […]

April 3, 2024

Laravel 11 Ajax CRUD Operation Tutorial Example

**Mastering CRUD Operations with Laravel 11 Ajax: A Comprehensive Tutorial** In the world of web development, interaction between the front-end […]

April 3, 2024

Login as Client in Laravel – Login with user id

**Unlock the Power of Laravel with Login as Client – Login with User ID** Laravel, the popular PHP framework, offers […]

April 3, 2024

Digital Marketing Toolkit

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

Get Free Access Now