DEV Community

Websolutionstuff
Websolutionstuff

Posted on • Originally published at websolutionstuff.com

How to Get Current URL in Laravel

In this small post we will see how to get current url in laravel, if you want to get current page url in laravel then we can use many method such type current(), full(), request(), url().

Here i will give you all example to get current page url in laravel, in this example i have used helper and function as well as so let's start example of how to get current url id in laravel.

Example 1 : full() with Helper and Query string parameters

$currenturl = url()->full();

dd($currenturl);
Enter fullscreen mode Exit fullscreen mode

Example 2 : current() with Helper

$currenturl = url()->current();

dd($currenturl);
Enter fullscreen mode Exit fullscreen mode

Example 3 : using Request

$currenturl = Request::url();

dd($currenturl);
Enter fullscreen mode Exit fullscreen mode

Example 4: current() with Facade

$currenturl = URL::current();

dd($currenturl);
Enter fullscreen mode Exit fullscreen mode

Example 5: full() with Facade and Query string parameters

$currenturl = URL::full();

dd($currenturl);
Enter fullscreen mode Exit fullscreen mode

Get Previous URL in Laravel

$pre_url= url()->previous();

dd($pre_url);
Enter fullscreen mode Exit fullscreen mode

Get Current Route in Laravel

$cur_route = Route::current()->getName();

dd($cur_route);
Enter fullscreen mode Exit fullscreen mode

Read More : Laravel 8 Autocomplete Search from Database


Read More : Laravel Signature Pad Example


Read More : How to Integrate Razorpay Payment Gateway in Laravel


Thanks for the reading...!!
Don't forgot to like,share and follow.

Discussion (0)