2017-03-17 148 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的幫助。我不知道這一點。 –

相關問題