How to Get Current Full URL in Laravel 10?

10-Apr-2023

.

Admin

How to Get Current Full URL in Laravel 10?

Hey Dev,

Laravel 10 get current url in controller is the focus of our discussion today. I made my explanation of how to view the current url in Laravel 10 simple. In this article, we'll use Laravel 10 to implement a retrieve current url. Laravel 10 retrieve current url can be seen. So, let's get started with the steps.

Laravel provides a URL facade that way we can get the current URL anywhere, as bellow you can see I use the current() URL facade. URL facade through which you can get your current page URL from every where. So you can check your current URL this way:

Get Current URL in Laravel:


Example 1: current() with Helper

$currentURL = url()->current();

dd($currentURL);

Example 2: full() with Helper(with query string parameters)

$currentURL = url()->full();

dd($currentURL);

Example 3: current() with Facade

$currentURL = URL::current();

dd($currentURL);

Example 4: full() with Facade(with query string parameters)

$currentURL = URL::full();

dd($currentURL);

Example 5: using Request

$currentURL = Request::url();

dd($currentURL);

Get Previous URL in Laravel:

$url = url()->previous();

dd($url);

Get Current Route in Laravel:

$route = Route::current()->getName();

dd($route);

I hope it can help you....

#Laravel 10