Redirect to previous page or url in laravel
Redirect to previous page or url in laravel
In this article, we will see how to solve "Redirect to previous page or url in laravel".
-
Redirect to previous page or url using web.php
--PATH routes\web.phpuse Illuminate\Support\Facades\Redirect; Route::get('/redirect-to-previous-url', function(){ return Redirect::to(url()->previous()); });
This code snippet helps you to redirect to the previous page or url in laravel. You have to use Redirect Fasade, use Illuminate\Support\Facades\Redirect; in your web.php file before Route definition. It will redirect you to the last visited url or page.
-
Redirect to previous page or url using controller’s method
--PATH app\Http\Controllers\<YourController>.php//Add before class defination use Illuminate\Support\Facades\Redirect; //Controller's method public function backToPreviousURL(){ return Redirect::to(url()->previous()); }
Redirecting users to the previous page or url in laravel is very easy. You have to use url()->previous() method on Redirect Fasade. url()->previous() method gives you the last visited page url and Redirect Fasade return you to that page. Add this code
use Illuminate\Support\Facades\Redirect;
before the class definition in your controller file. -
Redirect to previous url from view file in laravel
--PATH resources\views\<yourfile>.blade.php<a class="btn btn-info" href="{{ URL::previous() }}"> Back </a>
This code snippet will redirect you from current page to last visited page in laravel. On click anchor tag you will be redirected to previous page or url.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Return view from route Laravel
- How to get count of all records created at yesterday
- Automatically remove records using Prunable trait in Laravel
- Update email with unique validation in laravel
- Print last executed query in laravel
- Return redirect laravel not working
- Target class [HomeController] does not exist
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- Laravel onclick function not working
- Composer create project laravel/laravel example app
- How to insert dynamic value to additional column in pivot table in laravel
- How to send email in Laravel 11
- Get latest record by created at in Laravel
- Sample configuration files to create laravel project with docker using wsl (window subsystem linux)
- How to Run CRON Job on LIVE SERVER on Cpanel in Laravel Project
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- How to send email in laravel
- The use statement with non-compound name 'DB' has no effect
- Ignore Records where a field has NULL value in Laravel
- Pass value from controller to model in laravel
- How to update record after save method in Laravel
- How to check records exist in loaded relationship in Laravel blade view
- How to pass data to multiple partial view files in laravel