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....
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example