Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过路由中的设置通过url传递表单数据_Php_Laravel_Laravel 5_Laravel Routing - Fatal编程技术网

Php 通过路由中的设置通过url传递表单数据

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

我在我的Laravel项目中设置了一条路线,如果使用href,我会这样做
{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])
您想使用URL值作为输入值,所以在页面加载时,输入用URL值填充

  • 当您在路线中声明这些变量时,您的“目的地”路线控制器方法接受参数
    $country\u from
    $country\u to
    。这样,控制器中就有了这些变量,您可以清理它们,将它们绑定到返回的视图(例如:
    returnview('view',$data)
    returnview('view',compact('country\u from','country\u to'))
    ),并像往常一样在刀片服务器中访问它们
  • 您还可以使用
    \Request::route('country\u from')
    访问URL值。在将此值用作输入之前,应先对其进行清理
  • 使用刀片服务器中的这些变量作为输入
    属性,或
    占位符
    ,任何地方
    {{$country\u to}

如果这是您想要的路径,您需要javascript来获取用户输入和链接的值。或者。。将表单提交到一个单独的路由,然后使用已提交的参数重定向到目标路由,它将显示此url
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');