Friday, March 17, 2017

[SOLVED]htmlspecialchars() expects parameter 1 to be string, array given laravel

I'm trying to short records(tours) according to price (high to low and low to high) in search page, with a form that has submits on change event. Below is the code for the form:
{!!Form::open(['route' => 'short','method' => 'GET', 'role' => 'search','class'=>'select-filters'])!!}
    <input type="hidden" name=country value="">
    <input type="hidden" name=category value="">
    <input type="hidden" name=days value="">
    <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() !!}

and I've initialized the values in the same page but give the error htmlspecialchars() expects parameter 1 to be string, array given:
@if(Request::only('country') != null)
    
@else
    
@endif
@if(Request::only('category') != null)
    
@else
    
@endif
@if(Request::only('days') != null)
    
@else
    
@endif

The values in Request::only() is being passed from the search form in index page. When I die and dump:


I throws the incoming value in array form
enter image description here It dumps individual key value pair if i pass only one argument:
{{dd(Request::only('country'))}}
or
{{dd(Request::only('category'))}}
or
{{dd(Request::only('days'))}}

via Tanja Forsberg

Advertisement