【问题标题】:htmlspecialchars() expects parameter 1 to be string, array given laravelhtmlspecialchars() 期望参数 1 是字符串,数组给定 laravel
【发布时间】: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


【解决方案1】:

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

{{ request('country') }}

而不是这个:

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

【讨论】:

  • 感谢@Alexey 的帮助。我不知道这个。
猜你喜欢
  • 2018-02-22
  • 2018-11-10
  • 2017-03-22
  • 2017-07-12
  • 1970-01-01
  • 2017-08-30
  • 2018-07-30
  • 2018-08-04
  • 1970-01-01
相关资源
最近更新 更多