Muhammad Yasir Amin

Loading websiteโ€ฆ

More from Muhammad Yasir Amin

Build Along With Me

Practical walkthroughs on Laravel, React, APIs and deployment workflows.

Subscribe on YouTube

How to Get the Current URL in Laravel 13: url(), fullUrl() and Route Names

๐Ÿ› ๏ธ Laravel Tutorials4 min read

How to Get the Current URL in Laravel 13: url(), fullUrl() and Route Names

Muhammad Yasir Amin

Muhammad Yasir Amin

Senior Full Stack Engineerโ€ขNov 12, 2026
How to Get the Current URL in Laravel 13: url(), fullUrl() and Route Names

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:

Ruby
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();  // https

url()->current() and request()->url() both drop the query string. url()->full() and request()->fullUrl() keep it.

How do I use them in Blade?

CSS
<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:

JavaScript
request()->fullUrlWithQuery(['sort' => 'name']);
// https://example.com/products?page=2&sort=name

request()->fullUrlWithoutQuery(['page']);
// https://example.com/products?sort=price

How do I get the previous URL?

Code
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?

CSS
request()->route()->getName();   // products.index
Route::currentRouteName();         // products.index
Route::currentRouteAction();       // App\Http\Controllers\ProductController@index

The 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:

HTML / XML
<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:

JavaScript
<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:

Shell
->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?

  1. Create a temporary route: Route::get('/debug-url', fn () => [url()->current(), request()->fullUrl()]);.
  2. Open /debug-url?x=1 and compare the two values.
  3. 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.

References

Article Index & Topic Tags
LaravelBladeRoutingUrl

YouTube Channel

Build Along With Me

Practical walkthroughs on Laravel, React, APIs and deployment workflows.

Muhammad Yasir Amin
Available for Contracts
Author & Solutions Architect

Senior Full Stack Engineer

Independent Senior Full Stack Engineer working on Laravel, React and Next.js applications, APIs and delivery workflows.

Laravel & PHP ApplicationsReact & Next.js InterfacesREST APIs & IntegrationsDatabase Queries & DebuggingDocker Development WorkflowsClear Scope & Handover
Discuss Your Next Step

What Does Your Application Need Next?

Share your current system, the problem you want to solve and what a useful result looks like. We can identify the right starting point and agree on a practical scope.

Technical Audit

Find the Next Useful Fix

Application Development

Scoped, Reviewable Milestones

Ongoing Support

Agreed Capacity and Priorities

Share your goals, current stack and requirements before the call.