@cortez.connelly
In Laravel, you can use the previous()
method from the Redirect
facade to get the previous URL and then check and control it as needed. Here is an example of how you can do this:
1 2 |
use IlluminateSupportFacadesRedirect; use IlluminateHttpRequest; |
1
|
$previousUrl = url()->previous(); |
1 2 3 4 5 |
if ($previousUrl == route('your-route-name')) { // Do something if the previous URL matches a specific route name } else { // Do something else if the previous URL doesn't match the specific route name } |
1
|
return Redirect::back(); |
Note: When using Redirect::back()
, Laravel will automatically redirect the user to the previous URL or to the default URL if the previous URL is not available.
Remember to import the required classes and use them as shown in the example above.