How to Get Current URL in Laravel?

By Hardik Savani November 5, 2023 Category : Laravel

Hey Friends,

This article is focused on how to get current url in laravel controller. you can understand a concept of how to get current url in laravel blade. step by step explain how to get current url in laravel view. It's a simple example of laravel get current url in controller. So, let us see in detail an example.

We always require to get current URL path when work on ajax pagination or something, at that we require to get current page URL on Controller or blade file. So, you can get current url easily.

you can easily get current url in laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 application.

Laravel provide URL facade that way we can get current URL anywhere, as bellow you can see i use current() of URL facade. URL facade through 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....

Tags :
Shares