How to Get the Current URL in Laravel 10?

Spread the love

Hello Guys,

Today’s main focus is on getting the current URL in Laravel. I’ve streamlined the explanation of how to get the current URL in Laravel 10 within a view. This tutorial will guide you through the usage of Laravel 10’s current URL retrieval feature. Laravel 10 makes it easy to obtain the current visible URL. Let’s dive into the steps.

In the example below, you’ll see that we utilize the current() URL facade provided by Laravel to effortlessly access the current URL from any location. This URL facade allows you to retrieve your current page’s URL from anywhere. Here’s how you can ascertain your current URL:

Get the Current URL in Laravel:

Example 1: current() with Helper

Also Read: How to Get the Last Inserted Id in Laravel 10?

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

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

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

Example 3: current() with Facade

Also Read: How to DISABLE SPECIFIC DATES in Bootstrap Datetimepicker

$currentURL = URL::current();

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

$currentURL = URL::full();

Example 5: using Request

$currentURL = Request::url();

Get Previous URL in Laravel:

Also Read: How to Resize Images Before Upload in LARAVEL 10

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

Get Current Route in Laravel:

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

Discover the best in Laravel blog through our thoughtfully crafted content.

Leave a Comment