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') !!}


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 get data from a model on all pages in Laravel – Simple Way

Do you know How to get data from a model on all pages in Laravel ? In this blog post, […]

August 5, 2022

How to create a Laravel Collection From JSON

Today i have to create a laravel collection from a JSON object. I search on the internet and I cant […]

August 3, 2022

Laravel Eloquent WhereNull() and whereNotNull() Example

Do you know how to use WhereNull() and whereNotNull() Laravel Eloquent. In this post, I will explain how to use […]

July 28, 2022

Laravel Array to JSON Response From Laravel Controller

Do you know how to make JSON responses from a Laravel array? As a developer someday we all have to […]

July 28, 2022

Digital Marketing Toolkit

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

Get Free Access Now