Sitemap
We Code & We Write

Tell me and I forget. Teach me and I remember. Code with me and I learn.

7 Ways to Obtain the Current URL in Laravel

1 min readNov 7, 2022

--

In depth tutorial on Laravel URL

Press enter or click to view image in full size

When working on ajax pagination or another project, we constantly need to access the current page URL on the controller or blade file. As a result, getting the current URL is simple.

In the applications for Laravel 6, Laravel 7, Laravel 8, and Laravel 9, you can easily access the current URL.

As you can see in the example below, I used the current() method of the URL facade provided by Laravel to access the current URL from any location. You can obtain the current page's URL from anywhere using the URL facade. This is how you may determine your current URL.

How to get the current URL in Laravel

  1. Using url() helper‌
<p>The current URL is: {{url()->current()}}</p>

2. Current URL with query parameters using url() helper

<p>The current URL with parameters is: {{url()->full()}}</p>

3. Get current URL using URL facade

<p>The current URL is: {{URL::current()}}</p>

4. Full URL with query parameters using facade

<p>The current URL with parameters is: {{URL::full()}}</p>

Read the remaining at Quid Experience to support the creator, and enjoy Ad free experience!

--

--

We Code & We Write
We Code & We Write

Published in We Code & We Write

Tell me and I forget. Teach me and I remember. Code with me and I learn.

John Mwakalinga
John Mwakalinga

Written by John Mwakalinga

Developer. A bit biased to Laravel, JS and TS. I write about software and life topics. 🇹🇿. Checkout https://whenprogramming.com

No responses yet