To get the current URL with parameters, domain, etc in laravel; In this tutorial, we will learn how to get the current URL with parameters, current URL Path on controller and blade views in laravel 10|9|8 apps.
How to Get Current URL in Laravel 10|9|8
Using the following url()->full(), Request::url(), url()->current(), you can get url path in laravel 10|9|8 apps:
- Get Global and Current URL
- Get Current URL path
- Get the previous URL in Laravel
Get Global and Current URL
You can get current URL, global url with the query string in laravel apps using url(), url()->current, url()->full(); as follows:
echo \Request::url();
Use global url function
echo url()->url();
Use the current function
echo url()->current();
Get current full URL with query string parameters
echo url()->full();
Get Current URL path
Using the laravel path() method, you can get the current path of url in laravel:
$request->path()
Get the previous URL in Laravel
Sometimes you need to check what was the last requested or previous URL, it is simple to do in laravel here is how
echo url()->previous();
If you have any questions or thoughts to share, use the comment form below to reach us.