我有以下代码
在视图中
<form method="get" action="{{url('/submit-model')}}" class="form-horizontal form-label-left" id="">
<input name="_token" type="hidden" value="{!! csrf_token() !!}" />
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Select Brand</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="select_brand" class="select_brand form-control show-tick" data-live-search="true" name="brand_name">
@foreach($brandList as $key=>$val)
<option value="{{$val->id}}" >{{$val->brand_name}}-{{$val->id}}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Select Model</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="select_model" class="select_model show-tick form-control" data-live-search="true" name="model_name" >
</select>
</div>
</div>
<!-- <div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Select Model</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="brand_name" class="form-control col-md-7 col-xs-12"
name="brand_name" id="brand_name"
placeholder="Brand Name e.g Nokia" type="text" value="">
</select>
</div>
</div>--->
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<button id="send" type="submit" class="btn btn-success">Search</button>
</div>
</div>
</form>
路线
Route::get('mobiteam/submit-model/', 'MobiTeamController@submitModel');
在控制器
中 public function submitModel(Request $request){
print_r($request->all());
}
我的问题是
我如何使用用户友好的网址提交表单,如
路由:: get(&#39; / submit-model / {brandName} / {modelName}&#39;,&#39; MobiTeamController @ submitModel&#39;);
而不是
http://localhost/project/public/submit-model?_token=4LsaeqXbsjWLYf199LtSr7EgLacxhncNKde9Zpy2&brand_name=39&model_name=21
在ajax我可以,但我正在尝试没有ajax
答案 0 :(得分:2)
您将提交另一种方法并使用参数重定向到您的路线。
一般来说,你会这样做:
第1名:创建新路线:
// modify your route to:
Route::get('mobiteam/submit-model/{param1}/{param2}', [
'as' => 'mobiteam',
'uses' => 'MobiTeamController@submitModel'
]);
// add a new route:
Route::get('redirect-with-params', [
'as' => 'redirect',
'uses' => 'MobiTeamController@redirectWithParams'
]);
第二:提交到之前创建的路线(将重定向替换旧操作,如下所示):
<form method="get" action="{{route('redirect'}}" class="form-horizontal form-label-left" id="">
3nd:创建方法并使用params重定向:
// MobiTeamController.php
public function redirectWithParams(Request $request){
return \Redirect::route('mobiteam', ['param1' => $request->param1, 'param2' => $request->param2]);
}
就是这样!
答案 1 :(得分:2)
这不是常见请求,但您可以自己构建action
:
<form method="get" action="/submit-model/{{ $brand }}/"...>
你明白了。但@ Waiyl的答案更清晰。