How to get current url in laravel 8

How to get current url in laravel 8

Posted by Ervin Adams on June 6, 2022

There are a few basic ways to get current url in Laravel 8. You can put one of the the code snippets below in your controller and pass the url to your view.

You can use the Helper current method:

$url = url()->current();
print_r($url);
exit;

You can use the Helper full method:

$url = url()->full();
print_r($url);
exit;

You can use the Fascade current method:

use Illuminate\Support\Facades\URL;
...

$url = URL::current();
print_r($url);
exit;

You can use the Fascade full method:

use Illuminate\Support\Facades\URL;
...

$url = URL::full();
print_r($url);
exit;

You can use Request url method:

public function index(Request $request)
{
  ...
  
  $url = $request->url();
  print_r($url);
  exit;
}

Hopefully that was helpful.