输入表格作为参数Laravel Eloquent

时间:2016-05-28 10:18:34

标签: laravel

我想使用表单输入中的动态值进行动态查询

我的表单看起来像这样

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

路线

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

动作

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


}

我如何将表单中的数据作为min,max作为参数传递?

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

但我希望用户

从表单中动态填充

1 个答案:

答案 0 :(得分:1)

这样做的方法很少。

<强> 1。请求对象(推荐)。

public function search(Request $request)

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


}

或者:

public function search(Request $request)

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


}

<强> 2。输入外观。

public function search()

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

}

第3。 PHP $ _POST超全球。

public function search()

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

}