Laravel back to previous page; In this tutorial, we are going to show you how to back to previous page with data and without data in laravel apps.
To go back to the previous page in Laravel, you can use the back
method provided by Laravel’s redirector. This method will redirect the user back to the previous URL they were visiting.
You can use it like this:
return redirect()->back();
This code will create a redirect response to the previous URL. If there is no previous URL (for example, if the user landed directly on the current page), then the user will be redirected to the application’s homepage.
You can also pass data with the redirect like this:
return redirect()->back()->with('message', 'Your message here');
In this example, we are passing a message to the previous page using Laravel’s with
method. This message can be retrieved on the previous page using Laravel’s session
helper:
@if(session('message'))
<div class="alert alert-success">
{{ session('message') }}
</div>
@endif
This will display the message passed through the redirect on the previous page.
Be First to Comment