How to Get Current URL in Laravel?
This article is focused on how to get current url in laravel controller. you can understand a concept of how to get current url in laravel blade. step by step explain how to get current url in laravel view. It's a simple example of laravel get current url in controller. So, let us see in detail an example.
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, laravel 8, laravel 9 and laravel 10 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....
We are Recommending you
- Laravel Route Pass Multiple Parameters Example
- How to Get All Routes in Laravel?
- Laravel Download File from URL to Storage Example
- Laravel Redirect to Route from Controller Example
- Laravel Pagination Pretty URL Example
- Laravel URL Validation Rule Example
- Laravel Redirect to URL using redirect() Helper
- How to Get Current Controller Name in View Laravel?
- Laravel Get Route Parameters in Middleware Example
- How to Get a Current Page URL in PHP?
- How to Get Base URL in Laravel?
- How to Get URL Segment in Laravel?
- How to Get Current Route Name in Laravel?