Hi Guys,
Today, Laravel 10 gets the current URL in the controller is our main topic. I explained simply about Laravel 10 to get the current URL in view. In this article, we will implement a get current URL in Laravel 10. you can see Laravel 10 get the current URL. Alright, let’s dive into the steps.
Laravel provides a URL facade that way we can get the current URL anywhere, as bellow you can see I use the current() URL facade. URL facade through which you can get your current page URL from everywhere. So you can check your current URL this way:
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);
0 Comments
Leave a Comment