【发布时间】:2017-08-08 15:55:26
【问题描述】:
我正在尝试根据搜索页面中的价格(从高到低和从低到高)缩短记录(游览),并使用已提交更改事件的表单。下面是表单的代码:
{!!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'))}}
我将传入的值以数组形式抛出
{{dd(Request::only('country'))}}
或
{{dd(Request::only('category'))}}
或
{{dd(Request::only('days'))}}
【问题讨论】:
-
你的名字属性不带双引号!
-
抱歉让我更正一下。
标签: php arrays laravel laravel-5.4