【发布时间】:2019-01-10 19:07:43
【问题描述】:
我已经在我的 Laravel 项目中设置了一条路线,如果它使用 href 我会这样做 {{route('destination'),$country_from,$country_to}} 但现在我想将表单数据作为 $country_from 和 $country_to 传递请如何我这样做
<form action="{{route('destination')}}">
@csrf
<input type="text"
class="search-form flexdatalist"
name="origin"
placeholder="country_from"
data-search-in='name'
data-min-length='1'
/>
<img src="{{URL::asset('img/location.svg')}}" class="search-icon origin" width="28px" height="21px"/>
</div>
<div class=" col-md-3 mx-0 px-0">
<input type="text"
class="search-form flexdatalist"
name="country_to"
data-search-in='name'
data-min-length='1'
placeholder="Travelling to"
/>
<img src="{{URL::asset('img/location.svg')}}" class="search-icon destination" width="28px" height="21px"/>
</div>
<div class="col-md-3 mx-0 px-0">
<input type="text"
class="search-form flexdatalist"
name="residence"
data-search-in='name'
data-min-length='1'
placeholder="Residing In"
/>
<img src="{{URL::asset('img/location.svg')}}" class="search-icon residence" width="28px" height="21px"/>
</div>
<div class="col-md-3 px-0">
<input type="submit" value="Search Visas" class="btn btn-primary search-btn"/>
</form>
路线
Route::get('/{country_from}/{country_to}', 'DestinationCountriesController@index')->name('destination');
【问题讨论】:
-
如果这是您想要的路线,您将需要 javascript 来获取用户输入和链接的值。
-
或者.. 将表单提交到单独的路由,然后使用提交的参数重定向到目标路由
标签: php laravel laravel-5 laravel-routing