0

I want to dynamically query using dynamic values from form inputs

My form looks like this

<form action="{{url('search')}} method="post">
 <input name="min" type="number">
 <input name="max" type="number">
 <button type="submit">Submit</button>

Routes

Route::post('search', 'SearchController@search');

Action

public function search($min, $max)

{
   $max = //this should from form
   $min= //this should from form
   $result = $this->users->showResultByAgeMinMax($max,$min);//some code for repository


}

How whould I pass data from form as values for min, max as parameters?

 $min = 15;//works
 $max = 100;//works//

But I want this dynamically populated from form by a user

1
  • Also you need to pass csrf_token, just add input field to your form <input name="_token" type="hidden" value="{{ csrf_token() }}"> Commented May 28, 2016 at 11:33

1 Answer 1

1

There are few methods to do that.

1. Request object (recommended).

public function search(Request $request)

{
   $max = $request->input("max");
   $min= $request->input("min");
   $result = $this->users->showResultByAgeMinMax($max,$min);//some code for repository


}

Or:

public function search(Request $request)

{
   $max = $request->get("max");
   $min= $request->get("min");
   $result = $this->users->showResultByAgeMinMax($max,$min);//some code for repository


}

2. Input facade.

public function search()

{
   $max = Input::get("max");
   $min= Input::get("min");
   $result = $this->users->showResultByAgeMinMax($max,$min);//some code for repository

}

3. PHP $_POST superglobal.

public function search()

{
   $max = $_POST["max"];
   $min= $_POST["min"];
   $result = $this->users->showResultByAgeMinMax($max,$min);//some code for repository

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.