How to get current URL in controller or view in laravel ?

Today now in this post i will show you How to get current URL in controller or view in laravel ? We are always need to get the current URL path when work on any ajax pagination or something, at that time we need to get the current page URL on Controller or blade file. So, we can get current url easily.

We can easily get the current url in laravel 6, laravel 7 and laravel 8 any version of application.

Laravel provide us URL facade on that way we can get the current URL anywhere, as bellow we can see here i will use current() of URL facade. By using URL facade we can get our current page url from every where. So we can check our current url by 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();

Read Also: How to convert file extension using CloudConvert in laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →