How to get the current URL in Laravel
- Retrieve the Current URL in Laravel
- Get Current URL Without Query Paramteres
- Getting the Full URL Including Query Parameters
- Using the Request Instance
- Summary Reference
Retrieve the Current URL in Laravel
Accessing the current URL is a common requirement in Laravel applications whether for redirects, logging, analytics, or conditional logic. Laravel provides simple, expressive methods for retrieving the current URL, its full version with query strings, the base root, and even the previous page URL.
Get Current URL Without Query Paramteres
Laravel’s URL facade and the url() helper give you quick access to URL methods.
use Illuminate\Support\Facades\URL; // Get the current URL (without query parameters)$currentUrl = URL::current();
Example:
If your browser is at https://example.com/posts?page=2, URL::current() returns:
https://example.com/posts
The global helper syntax works the same:
$currentUrl = url()->current();
Both produce the same result.
Getting the Full URL Including Query Parameters
To include query parameters in the result, use the full() method.
$fullUrl = URL::full();
Example output:
https://example.com/posts?page=2&sort=latest
You can also use the Request instance for the same:
$fullUrl = request()->fullUrl();
Both return the complete URL including query strings.
Using the Request Instance
The Request object provides several methods for interacting with the URL and path.
Get the Current URL (without query)
$plainUrl = request()->url();
Equivalent to URL::current().
Get the Full URL (with query)
$fullUrl = request()->fullUrl();
Equivalent to URL::full().
Get Only the Path
$path = request()->path();
Example:
https://example.com/posts/42 → posts/42
Summary Reference
| Method | Returns | Includes Query String | Source |
|---|---|---|---|
URL::current() |
Current URL | No | URL Facade |
URL::full() |
Full URL | Yes | URL Facade |
request()->url() |
Current URL | No | Request |
request()->fullUrl() |
Full URL | Yes | Request |
request()->path() |
Path only | N/A | Request |
Stay Updated.
I'll you email you as soon as new, fresh content is published.