How to get the current URL of Laravel in controller and view?

In this blog, we will see how can we get the current URL of any Laravel site in the controller or in view.

We can get the current URL in Laravel 6, Laravel 7, Laravel 8, and Laravel 9 applications.

Get the Current URL in Laravel with the following code examples:

  1. current() with Helper
    $currentURL = url()->current();
    dd($currentURL);
  2. full() with Helper(with query string parameters)
    • $currentURL = url()->full();
    • dd($currentURL);
  3. current() with Facade
    • $currentURL = URL::current();
    • dd($currentURL);
  4. full() with Facade(with query string parameters)
    • $currentURL = URL::full();
    • dd($currentURL);
  5. using Request
    • $currentURL = Request::url();
    • dd($currentURL);
  6. Get Previous URL in Laravel:
    • $url = url()->previous();
    • dd($url);
  7. Get Current Route in Laravel:
    • $route = Route::current()->getName();
    • dd($route);

So, thanks for following this blog, and if you need any help please leave your queries in the comment box we will be happy to help you.

How to get the current URL of Laravel in controller and view?expoundsofttechsolution

d