Laravel 8 Get Current URL with Parameters Example

Laravel 6 , Laravel , Laravel 7 , Laravel 8

Nicesnippets

503

02-10-2020


Laravel 8 Get Current URL with Parameters Example

Hi Guys,

Today,I will learn you how to get current url with parameters in laravel 8.We will show example of get current url with parameters in laravel 8.I sometimes require to get full url path with query string parameters that way we can perform on it. So we can get current url with also all parameter using several method of laravel.

There are several option to get full url with query string as listed bellow:

-URL Facade

-Request Facade

-$request Object

I give you many ways to get full path with parameters, so you can see as bellow:

Example 1:


public function index()

{

$currentURL = \URL::current();

dd($currentURL);

}

Example 2:

public function index()

{

$fullUrl = \URL::full();

dd($fullUrl);

}

Example 3:

public function index()

{

$previousURL = \URL::previous();

dd($previousURL);

}

Example 4:

public function index()

{

$currentURL = \Request::url();

dd($currentURL);

}

Example 5:

public function index()

{

$fullUrl = \Request::fullUrl();

dd($fullUrl);

}

Example 6:

public function index()

{

$currentURL = \Request::segment(1);

dd($currentURL);

}

Example 7:

public function index(Request $request)

{

$currentURL = $request->url();

dd($currentURL);

}

Example 8:

public function index(Request $request)

{

$fullUrl = $request->fullUrl();

dd($fullUrl);

}

Example 9:

public function index(Request $request)

{

$currentURL = $request->segment(1);

dd($currentURL);

}

It will help you....


Recommended Posts