Laravel 7.x and 6.x get current url with parameters

August 25, 2017 | Category : Laravel 5.5 Laravel 5 Laravel PHP

Today, i am going to show you how to get current url, base url with parameter in your controller or view file. We may sometime need to get current url in controller method or maybe in blade file. So it's not difficult to do this thing in laravel 5.5 application.

Laravel provide Request and URL facade for getting request data. So we can simply get those current url using Request and URL facade. we can also get full url means you can get query string of url too. So i give you one by one both example As listed bellow:

Get Current URL with Parameters:

$currentURL = \Request::fullUrl();

dd($currentURL);

Get Current URL without Parameters:

$currentURL = \URL::current();

dd($currentURL);

OR

$currentURL = \Request::url();

dd($currentURL);

Get Only Parameters:

//www.domain.tld/post/list?page=2

$parameters = \Request::segment(3);

dd($parameters);

I hope you found your solutions....