Php 通过路由中的设置通过url传递表单数据
我在我的Laravel项目中设置了一条路线,如果使用href,我会这样做Php 通过路由中的设置通过url传递表单数据,php,laravel,laravel-5,laravel-routing,Php,Laravel,Laravel 5,Laravel Routing,我在我的Laravel项目中设置了一条路线,如果使用href,我会这样做{route('destination'),$country\u from,$country\u to},但现在我想将表单数据作为$country\u from和$country\u to传递,请问我该怎么做 <form action="{{route('destination')}}"> @csrf <input type="text
{route('destination'),$country\u from,$country\u to}
,但现在我想将表单数据作为$country\u from
和$country\u 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>
我不太明白你到底想做什么: 是否要在表单提交后将用户重定向到URL,并在重定向URL中使用表单值
- 在表单POST控制器中,从$request中检索输入并返回
return redirect()->route('route_name',['country_from'=>$request->country_from','country_to'=>$request->country_to])
- 当您在路线中声明这些变量时,您的“目的地”路线控制器方法接受参数
和$country\u from
。这样,控制器中就有了这些变量,您可以清理它们,将它们绑定到返回的视图(例如:$country\u to
或returnview('view',$data)
),并像往常一样在刀片服务器中访问它们returnview('view',compact('country\u from','country\u to'))
- 您还可以使用
访问URL值。在将此值用作输入之前,应先对其进行清理李>\Request::route('country\u from')
- 使用刀片服务器中的这些变量作为输入
属性,或值
,任何地方占位符
{{$country\u to}
http://localhost:8000/destination?_token=xKY7QEzceYP6zdYrtnNriOgbBbs9izeBeE6GyDQl&origin=Nigeria&flexdatalist-原产地=尼日利亚和国家/地区=澳大利亚和居住地=联合国+阿拉伯+酋长国
非/尼日利亚/联合+阿拉伯+酋长国
你想实现什么目标?第一个还是第二个?第二个,我试图实现第二个如果是第二个,我不知道重定向发生在哪里。第二个是关于在刀片服务器中使用URL值作为输入值。这是基于您的答案的代码公共函数重新路由(Request$Request){$country\u from=$Request->country\u from;$country\u to=$Request->country\u to;redirect()->路由('/{country\u from}/{country\u to}),['country\u from'=>country\u from',country\u to'=>country\u to];}
Route::get('/{country_from}/{country_to}', 'DestinationCountriesController@index')->name('destination');