In Laravel 13, use url()->current() to get the current URL without the query string, request()->fullUrl() to get it with the query string, and url()->previous() for the page the visitor came from. This article lists each method with its exact output, shows how to get the route name and how to mark the active menu link in Blade.
Targets: Laravel 13 (PHP 8.3 to 8.5). Every method here works in controllers, middleware and Blade views.
Which method returns what?
Assume the visitor opened https://example.com/products?page=2&sort=price:
url()->current(); // https://example.com/products
url()->full(); // https://example.com/products?page=2&sort=price
request()->url(); // https://example.com/products
request()->fullUrl(); // https://example.com/products?page=2&sort=price
request()->path(); // products
request()->getRequestUri(); // /products?page=2&sort=price
request()->getHost(); // example.com
request()->getScheme(); // httpsurl()->current() and request()->url() both drop the query string. url()->full() and request()->fullUrl() keep it.
How do I use them in Blade?
<p>You are on: {{ url()->current() }}</p>
<p>With query: {{ request()->fullUrl() }}</p>Both calls are safe to print with {{ }}, which escapes the value for HTML.
How do I add or remove a query parameter?
fullUrlWithQuery() returns the current URL with extra or changed parameters, which is handy for sort and filter links:
request()->fullUrlWithQuery(['sort' => 'name']);
// https://example.com/products?page=2&sort=name
request()->fullUrlWithoutQuery(['page']);
// https://example.com/products?sort=priceHow do I get the previous URL?
url()->previous();This uses the Referer header and falls back to the URL stored in the session. You can pass a fallback: url()->previous('/dashboard'). The helper back() redirects to the same place.
How do I get the current route name?
request()->route()->getName(); // products.index
Route::currentRouteName(); // products.index
Route::currentRouteAction(); // App\Http\Controllers\ProductController@indexThe route may be null in some contexts, for example in a middleware that runs before routing finishes, so use the null-safe operator when needed: request()->route()?->getName().
How do I mark the active link in a menu?
Use request()->routeIs() or request()->is(). Both accept patterns with the asterisk:
<a href="{{ route('products.index') }}"
class="{{ request()->routeIs('products.*') ? 'active' : '' }}">Products</a>
<a href="/blog"
class="{{ request()->is('blog*') ? 'active' : '' }}">Blog</a>Blade also has the @class directive, which keeps this tidy:
<a href="{{ route('products.index') }}" @class(['nav-link', 'active' => request()->routeIs('products.*')])>Products</a>Why does the URL show http instead of https?
When your app sits behind a load balancer or a proxy such as Cloudflare, PHP may see plain HTTP. Laravel then builds http:// links. Fix it by trusting the proxy in bootstrap/app.php and by setting the correct APP_URL:
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies(at: '*');
})Using '*' trusts every proxy. In production prefer the real proxy IP addresses. You can also force HTTPS for generated URLs in a service provider with URL::forceScheme('https').
When should I use url(), route() or asset()?
Use route('name') for pages of your own app, because the link keeps working if you later change the URL path. Use url('/path') when you only have a path, for example url('/about'). Use asset('css/app.css') for files in the public folder. All three build absolute URLs from the same base, which comes from the request in a web context and from APP_URL in console commands, queued jobs and scheduled tasks.
For links inside emails and notifications, which are built outside a web request, set APP_URL correctly, otherwise the links point to http://localhost.
How do I check that my code returns the right URL?
- Create a temporary route:
Route::get('/debug-url', fn () => [url()->current(), request()->fullUrl()]);. - Open
/debug-url?x=1and compare the two values. - Remove the route when you are done.
Common mistakes
- Using $_SERVER values directly: use the request object, which understands trusted proxies.
- Expecting the query string from current(): it never includes it. Use
fullUrl(). - Relying on previous() for security: the referer can be missing or changed. Do not use it to decide permissions.
- Wrong APP_URL:
url()helpers for console commands and queues use it, so keep it correct. - Calling route() on a null route: guard it in middleware.
FAQ
What is the difference between url()->current() and request()->url()?
For normal requests they return the same value. Use whichever reads better in your code.
How do I get only the path?
Use request()->path(), which returns the path without the leading slash, or request()->getPathInfo(), which keeps it.
How do I get the full URL in JavaScript?
Use window.location.href in the browser. Print server values into the page only when you need them.



