Laravel - How to get current URL in controller or view?
We always require to get current URL path when work on ajax pagination or something, at that we require to get current page URL on Controller or blade file. So, you can get current url easily.
you can easily get current url in laravel 6, laravel 7 and laravel 8 application.
Laravel provide URL facade that way we can get current URL anywhere, as bellow you can see i use current() of URL facade. URL facade through you can get your current page url from every where. So you can check your current url this way:
Get Current URL in Laravel:
Example 1: current() with Helper
$currentURL = url()->current();
Example 2: full() with Helper(with query string parameters)
$currentURL = url()->full();
Example 3: current() with Facade
$currentURL = URL::current();
Example 4: full() with Facade(with query string parameters)
$currentURL = URL::full();
Example 5: using Request
$currentURL = Request::url();
Get Previous URL in Laravel:
$url = url()->previous();
Get Current Route in Laravel:
$route = Route::current()->getName();
I hope it can help you....