2017-03-17 104 views
1

我试图根据价格(从高到低和从低到高)在搜索页面中记录(旅游),用提交更改的表单事件。下面是窗体的代码:htmlspecialchars()期望参数1是字符串,数组给定laravel

{!!Form::open(['route' => 'short','method' => 'GET', 'role' => 'search','class'=>'select-filters'])!!} 
    <input type="hidden" name="country" value="{{$country}}"> 
    <input type="hidden" name="category" value="{{$category}}"> 
    <input type="hidden" name="days" value="{{$days}}"> 
    <select name="sort_price" id="sort-price" onchange="this.form.submit()"> 
    <option value="" selected="">Sort by price</option> 
    <option value="lower">Lowest price</option> 
    <option value="higher">Highest price</option> 
    </select> 
{!! Form::close() !!} 

,我已经初始化值在同一个页面,但给错误htmlspecialchars() expects parameter 1 to be string, array given

@if(Request::only('country') != null) 
    {{$country = Request::only('country')}} 
@else 
    {{ $country = null }} 
@endif 
@if(Request::only('category') != null) 
    {{$category = Request::only('category')}} 
@else 
    {{ $category = null }} 
@endif 
@if(Request::only('days') != null) 
    {{$days = Request::only('days')}} 
@else 
    {{ $days = null }} 
@endif 

Request::only()值被从搜索表单传递在索引页面。当我死和转储:

{{dd(Request::only('country','category','days'))}} 

我抛出以阵列形式传入的值

enter image description here 它转储专用密钥值对,如果我只传递一个参数:

{{dd(Request::only('country'))}} 

 {{dd(Request::only('category'))}} 

 {{dd(Request::only('days'))}} 
+0

你的名字属性! –

+0

抱歉让我纠正它。 –

回答

1

only()总是返回一个数组,所以要得到一个字符串做到这一点:

{{ request('country') }} 

取而代之的是:没有双引号

{{ Request::only('country') }} 
+1

感谢@Alexey的帮助。我不知道这一点。 –

相关问题