Php Laravel,从url和表单向控制器传递多个输入值
我想将许多输入值传递给控制器,以便将它们与数据库中的值进行比较,同时我还想在url中发送ASE值,我是laravel的新手,所以请帮助我 路线:Php Laravel,从url和表单向控制器传递多个输入值,php,laravel,Php,Laravel,我想将许多输入值传递给控制器,以便将它们与数据库中的值进行比较,同时我还想在url中发送ASE值,我是laravel的新手,所以请帮助我 路线: Route::get('/store/caterer_search/{filter?}','HomeController@StoreSearch'); <form class="order-box__input-wrapper" name="form_mainpage" id="form_mainpage" action="/store/cat
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'));
}
表格:
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'));
}
您能使用
表单::open()
吗?它可能有用
Form::open(['route' => ['HomeController.StoreSearch', $autocomplete, $some_other_parameter]])
您能使用
表单::open()
吗?它可能有用
Form::open(['route' => ['HomeController.StoreSearch', $autocomplete, $some_other_parameter]])
你有一些错误
- 如果使用“GET”方法,则不能使用enctype属性的
值。在这种情况下,您没有输入文件字段,因此可以删除该属性multipart/form data
- 这些输入:
是无用的。它们没有类型,因此不会发送到表单。如果它们是隐藏字段,则必须向其添加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'));
}
正如您所看到的,路由的过滤器
参数非常无用,我不知道您为什么要添加到路由中
在控制器函数中,您可以使用以下代码获取输入参数:
$request->input("name_of_the_field", "default_value");
你有一些错误
- 如果使用“GET”方法,则不能使用enctype属性的
值。在这种情况下,您没有输入文件字段,因此可以删除该属性multipart/form data
- 这些输入:
是无用的。它们没有类型,因此不会发送到表单。如果它们是隐藏字段,则必须向其添加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'));
}
正如您所看到的,路由的过滤器
参数非常无用,我不知道您为什么要添加到路由中
在控制器函数中,您可以使用以下代码获取输入参数:
$request->input("name_of_the_field", "default_value");
Im获取错误:为foreach()提供的参数无效{“异常”:“[object](ErrorException(代码:0):为foreach()提供的参数无效)即使是我,我也不使用foreach,但不知道我为什么会遇到这个错误你的解决方案对我不起作用,url非常复杂,我不知道如何修复它,我想像Ezcatet.com一样使用搜索时重定向到url这样:url不重要。试着解释一下你想做什么,你尝试了什么,为什么我的代码不起作用这不是很好,但是我想把url改短一些,希望你能帮我解决这个问题。错误:为foreach()提供的参数无效{“exception”:“[object](ErrorException(代码:0):为foreach()提供的参数无效)即使是我,我也不使用foreach,但不知道我为什么会遇到这个错误你的解决方案对我不起作用,url非常复杂,我不知道如何修复它,我想像Ezcatet.com一样使用搜索时重定向到url这样:url不重要。试着解释一下你想做什么,你尝试了什么,为什么我的代码不起作用It’这不是很好,但是我想把url改短一些,希望你能在这方面帮助我