Laravel provides several closely related ways to get the current request's URL — the specific difference between them (whether query parameters are included, whether it's a full URL or just a path) matters for getting an "active nav link" or "preserve current filters" feature exactly right.
The current URL without query parameters
url()->current()
// or
$request->url()
// For https://example.com/products?category=electronics&sort=price
// Returns: https://example.com/products
The full current URL, including query parameters
url()->full()
// or
$request->fullUrl()
// Returns: https://example.com/products?category=electronics&sort=price
Just the path, without domain or query string
$request->path()
// Returns: products (no leading slash, no domain, no query string)
Highlighting the active navigation link
Products
request()->is() checks the current path against a pattern, supporting a trailing * wildcard — request()->is('products*') would also match /products/123, useful for keeping a parent nav item highlighted while on any of its sub-pages.
Checking the current route by name, rather than by URL pattern
Products
routeIs() checking the route's registered name (rather than the literal URL string) is generally the more robust choice — it keeps working correctly even if the actual URL pattern changes later, as long as the route's name itself stays the same.
Preserving the current query string when generating a link
Sort by price
array_merge() with request()->query() preserves every other currently active query parameter while changing just the one being updated — without this merge, changing the sort order would silently drop any other active filter (like a category selection) from the URL.
Getting a specific query parameter's value
$search = request()->query('search');
$search = $request->input('search'); // also checks POST body, not just query string
Redirecting back to the current URL after an action
return redirect(url()->current());
// or, more commonly, simply:
return back();
back() is generally preferable to manually reconstructing url()->current() — it uses the HTTP referer header (or a configured fallback) and correctly preserves any query string or form input the user had, which is exactly the behavior wanted after handling a form submission that should return to where the user came from.
Getting the current URL from within a Blade template directly
This is genuinely useful for setting a canonical URL tag for SEO purposes — deliberately using current() (without query parameters) rather than full() here is usually correct, since a canonical tag typically shouldn't vary based on tracking or filter query parameters that don't represent meaningfully different content.