How to Get Current URL in Laravel?
Hey Friends,
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, laravel 10 and laravel 11 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();
dd($currentURL);
Example 2: full() with Helper(with query string parameters)
$currentURL = url()->full();
dd($currentURL);
Example 3: current() with Facade
$currentURL = URL::current();
dd($currentURL);
Example 4: full() with Facade(with query string parameters)
$currentURL = URL::full();
dd($currentURL);
Example 5: using Request
$currentURL = Request::url();
dd($currentURL);
Get Previous URL in Laravel:
$url = url()->previous();
dd($url);
Get Current Route in Laravel:
$route = Route::current()->getName();
dd($route);
I hope it can help you....
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
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?