1

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="{{$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() !!}

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)
    {{$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

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

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

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'))}}
2
  • your name attributes without double quote! Commented Mar 17, 2017 at 7:33
  • sorry let me correct it. Commented Mar 17, 2017 at 7:35

1 Answer 1

1

only() always returns an array, so to get a string do this:

{{ request('country') }}

Instead of this:

{{ Request::only('country') }}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Alexey for your help. I didn't knew this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.