当我提交GET方法表单时,url生成如:
example.com/machine?brand=xx&model=2016&color=red&km=110
但我想生成像:
这样的网址example.com/machine/xx/2016/red/km=110
我的路线:
Route::get('/machine/{brand}/{model}/{color}/{km}',['as'=>'machine.search','uses'=>'searchController@searchmachine']);
表格:
{!! Form::open(['route'=>'machine.search','method'=>'GET','class'=>'form-horizontal','role'=>'form']) !!}
答案 0 :(得分:0)
你必须在JS中做到这一点。这是表格
<form action="machine">
<input name="brand"/>
<input name="model"/>
<input name="color"/>
<input name="km"/>
<button type="submit" onclick="window.location.href=this.form.action + this.form.brand.value + this.form.model.value + this.form.color.value + this.form.km.value;">
Submit
</button>
</form>
提交按钮将生成网址
http://website.com/machine/brandvalue/modelvalue/colorvalue/kmvalue
在您的情况下,您通过将route
替换为url
来重新填写表单,因为使用route
会要求您传递参数
{!! Form::open(['url'=>'machine','method'=>'GET','class'=>'form-horizontal','role'=>'form']) !!}
答案 1 :(得分:0)
您没有使用良好的做法进行搜索,首先您的路线必须如下所示:
Route::get('/machine/search',['as'=>'machine.search','uses'=>'searchController@searchmachine']);
然后在你的searchController中:
class searchController extends Controller {
public function searchmachine(Request $request)
{
$brand = $request->brand;
$model = $request->model;
$km = $request->km;
$color = $request->color;
//Do your things.
}
}
这应该有效:
example.com/machine/search?brand=xx&model=2016&color=red&km=110