ItSolutionStuff.com

How to Get Current URL in Laravel?

By Hardik Savani • April 16, 2024
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, laravel 10 and laravel 11 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: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Route Pass Multiple Parameters Example

Read Now →

How to Get All Routes in Laravel?

Read Now →

Laravel Download File from URL to Storage Example

Read Now →

Laravel Redirect to Route from Controller Example

Read Now →

Laravel Pagination Pretty URL Example

Read Now →

Laravel URL Validation Rule Example

Read Now →

Laravel Redirect to URL using redirect() Helper

Read Now →

How to Get Current Controller Name in View Laravel?

Read Now →

Laravel Get Route Parameters in Middleware Example

Read Now →

How to Get a Current Page URL in PHP?

Read Now →

How to Get Base URL in Laravel?

Read Now →

How to Get URL Segment in Laravel?

Read Now →

How to Get Current Route Name in Laravel?

Read Now →