我想将许多输入值传递给控制器,所以我想将它们与数据库中的值进行比较,我也想在url中发送asease值,我是laravel的新手,所以请帮助我
路线:
Route::get('/store/caterer_search/{filter?}','HomeController@StoreSearch');
表格:
<form class="order-box__input-wrapper" name="form_mainpage" id="form_mainpage" action="/store/caterer_search/" method="get" enctype="multipart/form-data" autocomplete="off">
{{ csrf_field() }}
<div class="order-box__input">
<div class="address-bar-input">
<input type="text" aria-label="Enter address" id="autocomplete" onFocus="geolocate()" name="autocomplete" placeholder="Enter your delivery address" data-role="address-field" onClick="this.select();">
<input class="field" id="city" hidden=""></input>
<input class="field" id="street_number" disabled="true" hidden=""></input>
<input class="field" id="route" disabled="true" hidden="" ></input>
<input class="field" id="locality" disabled="true" name="locality" ></input>
<input class="field" id="administrative_area_level_1" disabled="true"name="administrative_area_level_1"></input>
<input class="field" id="postal_code" disabled="true" name="postal_code" ></input>
<input class="field" id="country" disabled="true" hidden=""></input>
</div>
</div>
<i class="icon icon-location"></i>
<button type="submit" id="homesearchbtn" class="btn btn--primary order-box__submit" aria-label="Search for caterers" disabled="">Search</button>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
控制器:
public function StoreSearch($autocomplete,$locality,$administrative_area_level_1,$postal_code)
{
$stores = Storeinfo::getStoreByLocation($autocomplete);
return view('hotels.archive',compact('hotel','country','city','star'));
}
答案 0 :(得分:0)
您可以使用Form::open()
吗?可能有效。
Form::open(['route' => ['HomeController.StoreSearch', $autocomplete, $some_other_parameter]])
答案 1 :(得分:0)
您有一些错误。
multipart/form-data
值。在这种情况下,您没有输入文件字段,因此可以删除属性<input class="field" id="country" disabled="true" hidden=""></input>
是无用的。它们没有类型,因此不会发送到表单。如果它们是隐藏字段,则必须向其中添加type="hidden"
您以这种方式定义了路线:
Route::get('/store/caterer_search/{filter?}','HomeController@StoreSearch');
所以控制器应该像这样:
public function StoreSearch(Request $request, $filter = null) {
//
$autocomplete = $request->input("autocomplete", "");
$stores = Storeinfo::getStoreByLocation($autocomplete);
return view('hotels.archive',compact('hotel','country','city','star'));
}
如您所见,路由的filter
参数几乎没有用,我不知道您为什么添加到路由。
在控制器功能内,您可以通过以下代码获取输入参数:
$request->input("name_of_the_field", "default_value");