HDTuto.com

Laravel 5.7 Get Current URL with Parameters


Hi Developer,

In this small post, i wanted to show you how you can get current url or base url with parameters in your controller file or blade view file of laravel 5.7 project. So laravel 5.7 provide several way to get current app path using fullUrl(), current(), url() and segment() of request object. You can easily get by request object.

Laravel 5.7 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:

//Example URL: www.domain.tld/post/list?page=2

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

dd($parameters);

I hope you found your solutions....






September 25, 2018 | Category : PHP Laravel Laravel 5 Laravel 5.7
Related Posts