How to Get Current URL Without Domain in Laravel 12
In this Laravel 12 guide, we’ll show you how to retrieve the current URL without the domain name. Laravel provides several convenient…
How to Get Current URL Without Domain in Laravel 12

In this Laravel 12 guide, we’ll show you how to retrieve the current URL without the domain name. Laravel provides several convenient methods to extract just the URL path. We’ll walk through how to implement this in both your Blade templates and controller logic using helper functions and the request object.
Sometimes, you only need the path portion of a URL in your Laravel application — without the domain or query parameters. This is especially useful when your app is deployed across different domains or environments, where hardcoding the full URL could lead to broken links. Using just the relative path (like /dashboard) keeps your codebase more flexible and portable.
Laravel provides clean and straightforward ways to achieve this using the Request object and URL helper methods.
In this tutorial, we’ll walk through these techniques step by step, along with clear code examples. We’ll also compare full URLs and path-only outputs so you can easily see the difference and understand when to use each.
This approach works seamlessly in Laravel 10, Laravel 11, and Laravel 12.
Below, you’ll find two simple ways to get the current URL path — both in Blade views and controller methods — using Laravel’s built-in functionality.
Example 1: Laravel Get Current URL Without Domain in Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class DemoController extends Controller
{
public function getUrl(Request $request)
{ //first method to get current url without domain
$withoutDomainURL = request()->path();
//second method to get url without domain
$withoutDomainURL2 = $request->path();
dd($withoutDomainURL,$withoutDomainURL2);
}
}
In the example above, we used the DemoController to illustrate how to retrieve the current URL without the domain in Laravel. The first approach uses the request() helper function, while the second leverages the $request object directly. Both methods are valid — you can choose whichever fits your coding style or context best.
For instance, given the input URL: http://127.0.0.1:8000/url-example
The output will be:
url-example
Example 2: Laravel Get Current URL path in Blade
<!-- resources/views/welcome.blade.php -->
<!DOCTYPE html>
<html>
<head>
<title>Current URL Path</title>
</head>
<body>
<h1>Get Current URL Path (Without Domain)</h1>
<p>
Path: <strong>{{ request()->path() }}</strong>
</p>
</body>
</html>
In the Blade view, we used the request() helper function to retrieve the current URL path without the domain.
Input URL: http://127.0.0.1:8000/welcome-page
Output: welcome-page
Conclusion
Getting the current URL path without the domain in Laravel is simple and efficient, thanks to built-in features like the request()->path() helper and the $request object. Whether you’re inside a controller or a Blade view, Laravel offers clean and intuitive methods to retrieve just the path segment of the URL. This makes it easy to build features like active route highlighting, breadcrumbs, or custom redirects — without depending on the full domain structure.
메타데이터
- post_id
- 400b937a1011
- slug
- how-to-get-current-url-without-domain-in-laravel-12-400b937a1011
- url
- https://medium.com/@itstuffsolutions/how-to-get-current-url-without-domain-in-laravel-12-400b937a1011
- canonical_url
- https://medium.com/@itstuffsolutions/how-to-get-current-url-without-domain-in-laravel-12-400b937a1011
- author_url
- https://medium.com/@itstuffsolutions
- status
- ok
- fetched_at
- 2026-08-06 10:54:58