Hello today short tutorial is how to get the current URL which live on your browser in Laravel. In some case you want to retrieve the URL link from browser bar which mean current URL. In this article you will see how to get current URL in different ways by following sample example which you can apply in Laravel 6, Laravel 7, Laravel 8, Laravel 9
Laravel support helper class and URL facade which we will use to get current URL anywhere. Let's check the below examples:
Using current() with Helper
$currentURL = url()->current();
dd($currentURL);
Using full() with Helper (include query string)
$currentURL = url()->full();
dd($currentURL);
Using current() with Facade
$currentURL = URL::current();
dd($currentURL);
Using full() with Facade (include query string)
$currentURL = URL::full();
dd($currentURL);
Using Request
$currentURL = Request::url();
dd($currentURL);
$route = Route::current()->getName();
dd($route);
$url = url()->previous();
dd($url);
Hope these examples help you. Have a nice day!!
You might also like
Founder of CamboTutorial.com, I am happy to share my knowledge related to programming that can help other people. I love write tutorial related to PHP, Laravel, Python, Java, Android Developement, all published post are make simple and easy to understand for beginner. Follow him