Laravel 9 Get Current URL with Parameters Example

May 09, 2022 . Admin

Hi Guys,

Today, I will learn you how to get the current url with parameters in laravel 9. We will show an example of get the current url with parameters in laravel 9. I sometimes require to get a full url path with query string parameters that way we can perform on it. So we can get the current url with also all parameters using several methods of laravel.

There are several options to get a full url with a query string as listed below:

-URL Facade

-Request Facade

-$request Object

I give you many ways to get the full path with parameters, so you can see as below:

Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app
Example 1:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index()
{
    $currentURL = \URL::current();
    dd($currentURL);
}
Example 2:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index()
{
    $fullUrl = \URL::full();
    dd($fullUrl);
}
Example 3:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index()
{
    $previousURL = \URL::previous();
    dd($previousURL);
}
Example 4:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index()
{
    $currentURL = \Request::url();
    dd($currentURL);
}
Example 5:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index()
{
    $fullUrl = \Request::fullUrl();
    dd($fullUrl);
}
Example 6:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index()
{
    $currentURL = \Request::segment(1);
    dd($currentURL);
}
Example 7:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index(Request $request)
{
    $currentURL = $request->url();
    dd($currentURL);
}
Example 8:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index(Request $request)
{
    $fullUrl = $request->fullUrl();
    dd($fullUrl);
}
Example 9:
<?php

/**
 * Write code on Method
 *
 * @return response()
 */
public function index(Request $request)
{
    $currentURL = $request->segment(1);
    dd($currentURL);
}

It will help you...

#Laravel 9