How do I get current URL in Laravel Controller or View?

Published January 17, 2022

In this tutorial, we'll look at how to access the current URL in a Laravel Controller or view. Laravel includes several ways for obtaining the current uri.

  • Request::path(),
  • Request::segment(),
  • Request::is(), and
  • Request::fullUrl()

In this tutorial, we will use Request::fullUrl() to access the current Uri of theLaravel Controller. Let's have a look at the simple steps below:

 

Step 1:Open your composer command prompt and execute the following command to create a  new Laravel project

 

composer create-project --prefer-dist laravel/laravel currenturl

 

Step 2: Now, Open your, welcome.blade.php file and add the following code to display the current uri

<p> Url: {{  Request::url() }} </p>

 

Now open your application in the browser. The project URL will be displayed.

 

How do I get current URL in Laravel Controller or View

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

789 Views