Laravel 6 Get Request Parameters in Controller

Admin   Laravel   454  2021-03-17 05:30:09

Hii guys,

In this blog,I will teach you how to get request parameters in Laravel 6.If you get query string value then you can get using Request Facade OR Input Facade in larave 6.

Laravel 6 in You can url in pass parameters if you get parameters value then use bellow example.

In bellow example you can easily get request parameters values.

First you can create route in web.php file.

routes/web.php

 

Route::get('contact-us','[email protected]');

you can create contactUs method in controller file.In this example in use HTTP Request.

Example 1

 

public function contactUs(Request $request)

{

$allParameters = $request->all();

dd($allParameters);

}

Output

 

array:3 [?

"id" => "2"

"name" => ""xyz""

"msg" => ""hiii""

]

Second example in you can use Input method to get parameters value.

Example 2

 

public function contactUs(Request $request)

{

$allParameters = Input::all();

dd($allParameters);

}

Output

 

array:3 [?

"id" => "2"

"name" => ""xyz""

"msg" => ""hiii""

]

In this solution you can use HTTP Request in query to get url parameters.

Example 3

 

public function contactUs(Request $request)

{

$allParameters = \Request::query();

dd($allParameters);

}

Output

 

array:3 [?

"id" => "2"

"name" => ""xyz""

"msg" => ""hiii""

]

Bellow example in perticuler parameters get to $_GET use.

Example 4

 

public function contactUs(Request $request)

{

$id = $_GET['id'];

dd($id);

}

Output

 

"2"

In this Example in HTTP Request in input() used.

Example 5

 

public function contactUs(Request $request)

{

$allParameters = $request->input();

dd($allParameters);

}

Output

 

array:3 [?

"id" => "2"

"name" => ""xyz""

"msg" => ""hiii""

]

It will help you...