How do I get Query String values in Laravel?

Published January 19, 2022


In this article, I'll teach you how to obtain the value of a query string in Laravel. In a Laravel application, you can access the Query string value either through using Request Facade or by using Input Facade. However, if you are using native PHP, then you can get this information by using the $_GET function.

So, let's take a look at the example below. In the example below, we can efficiently determine the parameter value.

Example

Using the example id and name from the query string above, we can now get the query string value for each. The following example demonstrates how to do this.

Step 1: Create a new Laravel project using the following command

composer create-project --prefer-dist laravel/laravel Querystring.

 

Our project has been successfully created

Step 2:Open your Route/web.php and add the following Route.

Route::get('wall', 'WallController@wall');

Step 3: Now, open your controller and add the following code

public function wall(Request $request)

{

  /* returns Ony Id value */

  $id = $request->input('id');

  /* returns array of entire input query value */

  $query = $request->all();

  /* To returns Ony Id value */

  $id = Input::get('id');

  /* returns array of entire input query value */

  $query = Input::all();

}

 

 

Step 4: Now ran  the command php artisan serve to get the project URL

How do I get Query String values in Laravel

Run the project url to get the Query string parameters

 

How do I get Query String values in Laravel2

 

Conclusion: We covered in this laravel tutorial to how to get query parameters from the requested url

 


Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

374 Views

Subscribe For Daily Updates

Flutter Questions
Android Questions