How to Get Current URL With Query String in Laravel 8?

Share Me
  •  
  •  
  •  
  • 2
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    2
    Shares
How to Get Current URL With Query String in Laravel

Now today in this Example, I will show you how to get current url also with query string in laravel 8 application. Here we can do it simply also get current full url by using Request in laravel 8 application.Here we know How to Get Current URL With Query String in Laravel 8 application.

Now i need many times to get current url and query string, So we can get url query string by using helper function of \Request::fullUrl().

Step1:Create Route

Now we will create to route in routes/web.php in file.

Route::get('/route',"RouteController@index")->name('route.test');  

Step2:Create Controller

Next we will create to controller app/Http/RouteController.php in file.

php artisan make:controller RouteController   

Example 1:

Now i will just use the fullUrl() method in this example.

/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index(Request $request)
{
   $getQueryString=\Request::fullUrl();

   dd($getQueryString); 
}

Output

"http://localhost:8000/route?id=1&name=code_master"

Example 2:

Here I will use the getRequestUri() method in this example.

/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index(Request $request)
{
   $getQueryString=\Request::getRequestUri();
   
   dd($getQueryString); 
}

Output

"http://localhost:8000/route?id=1&name=code_master"

Example 3:

I will use the url()->full() method in this example.

/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index(Request $request)
{
   $getQueryString=url()->full();
   
   dd($getQueryString); 
}

Output

"http://localhost:8000/route?id=1&name=code_master"

Read Also : How to disable specific Dates in Bootstrap Datepicker

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 →