How to Get Current URL in Laravel

Websolutionstuff | Mar-10-2021 | Categories : Laravel PHP

In this article, we will see how to get the current URL in laravel. If you want to get the current page URL in laravel then we can use many methods such as type current(), full(), request(), url(). Also, you can get the current URL in laravel 6, laravel 7, and laravel 9.

Here, we will give you all examples to get the current page url in laravel. In this example, we have used the laravel helper function. Also, you can get the previous URL and full URL in laravel 6/7/8/9.

So, let's see laravel 7/8/9 get the current URL and get the full URL in laravel.

Example 1:  full() with Helper and Query string parameters

In this example, we will use the full() laravel helper function and get the full URL.

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

dd($currenturl);

 

Example 2: current() with Helper

In this example, we will use the url() function with the current() helper function and get the current URL.

$currenturlĀ = url()->current();

dd($currenturl);

 

Example 3: using Request

In this example, we will get the url using the request method.

$currenturl = Request::url();

dd($currenturl);

 

 

Example 4: current() with Facade

In this example, we will use the URL facade and get the current URL.

$currenturl = URL::current();

dd($currenturl);

 

Example 5: full() with Facade and Query string parameters

 In this example, we will use the URL facade and get the full URL.

$currenturl = URL::full();

dd($currenturl);

 

Example 6: Get Previous URL in Laravel

In this example, we will use the url() function and get the previous URL.

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

dd($pre_url);

 

Example 7: Get Current Route in Laravel

Now, we will get the current route using the getName() function.

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

dd($cur_route);

 


You might also like:

Recommended Post
Featured Post
Laravel 10 Delete Multiple Records Using Checkbox
Laravel 10 Delete Multiple Rec...

In this article, we will see laravel 10 delete multiple records using the checkbox. Here, we will learn about how to del...

Read More

Mar-03-2023

How To Send Email using Node.js
How To Send Email using Node.j...

Hello Friends, In this tutorial we will learn how to send email using node.js app. In this tutorial we will see send...

Read More

Jul-28-2021

How to Get Last 15 Records in Laravel 10
How to Get Last 15 Records in...

Welcome, fellow developers! In this guide, I'll walk you through the straightforward process of fetching the latest...

Read More

Dec-08-2023

How to Install Select2 in Laravel 10 Example
How to Install Select2 in Lara...

Hey there, Laravel enthusiasts! If you're looking to add a touch of elegance and user-friendliness to your web...

Read More

Feb-14-2024