Avatar of Soumaya Hachem
Soumaya Hachem

asked on 

Method appends does not exist -LARAVEL Elasticsearch

Hi, I want to select all hotels where minrate between 0 and 49 it marche perfectly , but when i want to select all hotels where minrate between 0-49 and 50-99 It is you to say when it enters the loop "for" it return this error

ErrorException in Macroable.php line 74:
Method appends does not exist. (View: C:\xampp\htdocs\elasticsearch\resources\views\presult.blade.php) (View: C:\xampp\htdocs\elasticsearch\resources\views\presult.blade.php)

Function Laravel
public function pricefilter(Request $request)
    {
         $query = Input::get('query', false);
       $brans = request()->priceFilter;
         $books = new Collection(); 
if(!empty($brans))
        { 
            $product = "";

foreach($brans as $data){
               $minMax = explode("-",$data);
              
            
                $product[] = Afica::search()
                    ->multiMatch(['name','city_hotel'], $query, ['fuzziness' => 'AUTO'])
                    ->filter()
                    ->range('minrate',['from'=>$minMax[0],'to'=>$minMax[1]])
                    ->paginate(26)
                    ->appends('priceFilter' , request('priceFilter'));
            
            
                
     
         }
          $books= $product[0];
          for($i=1;$i<count($product);$i++){
              $books=$books->union($product[$i]);
        

          }
         }
        else 
        {
               $books = Afica::search()
            ->paginate(26);
   
        
        }
        if ($request->ajax())
        {
                return view('presult', compact('books'));
        }
        return view('welcome',compact('books')); 
        
    }

Open in new window

View presult
 <!--deal-->    
            <?php $myArray = array();?>

            @if  (empty($myArray))
            
            @foreach($books as $Afica)
            <?php $collection = collect($Afica);?>
            <article class="one-third">
              <figure><a href="#" title=""><img src="{{ $collection->get('photo_url') }}" alt="" style="height: 215px!important;" /></a></figure>

              <div class="details">
           
                <h3>{{{  $collection->get('name') }}}
                  <span class="stars">
                 
                      <?php 

                      for ($i=1 ; $i<= $collection->get('class') ; $i++) 
                      {
                      echo ' <i class="material-icons">&#xE838;</i>';
                      }
                  
                  ?>
                  </span>
                </h3>
                <span class="address">{{{  $collection->get('city_hotel') }}},{{{  $collection->get('address') }}}  <a href="">Show on map</a></span>
                <span class="rating">{{{  $collection->get('preferred') }}}</span>
                <span class="price">Max rate  <em>$ {{{  $collection->get('maxrate') }}}</em> </span>
                <span class="pricee">Min rate  <em>$ {{{  $collection->get('minrate') }}}</em> </span>
                <div class="description">
                  <p>{{{  $collection->get('desc_en') }}}<a href="hotel?query= $collection->get('name')">More info</a></p>
                </div>   
                <a href="{{{ $collection->get('hotel_url') }}}" title="Book now" class="gradient-button">Book now</a>
              </div>
            </article><?php $myArray[] =  $collection->get('id');?>

            <!--//deal-->
            @endforeach

           @endif
           
    
 
          
            <!--//bottom navigation-->
             <div class="bottom-nav">
            <a href="#" class="scroll-to-top" title="Back up">Back up</a> 
            <div class="pager">
            <?php $query=Input::get('query', '');?>
            @if($query == "")
          <span><a href="?page=1">First Page</a></span>
            @else
         <span><a href="?query=<?php echo $query?>&page=1"=>FirstPage</a></span>
         @endif
       {!! $books->appends(['query' => Input::get('query')])->render() !!}
       @if($query == "")
          <span><a href="?page={!! $books->appends(['query' => Input::get('query')])->lastPage() !!}">Last Page</a></span>
            @else
         <span><a href="?query=<?php echo $query?>&page={!! $books->appends(['query' => Input::get('query')])->lastPage() !!}">Last Page</a></span>
         @endif
            <!--bottom navigation-->
              </div>
         </div>    
            <!--//bottom navigation-->

Open in new window


View Welcome

@extends('layouts.app')

@section('content')
@include('include.header') 
@include('include.slider') 
       @include('include.search') 
<div class="container-fluid">

        <div class="container">
            <div class="content">
          <!--main-->
  <main class="main">   
    <div class="wrap">
      <!--breadcrumbs-->
      <nav class="breadcrumbs">
        <!--crumbs-->
        <ul>
          <li><a href="#" title="Home">Home</a></li>
          <li><a href="#" title="Hotels">Hotels</a></li>
          <li><a href="#" title="United Kingdom">United Kingdom</a></li>
          <li><a href="#" title="London">London</a></li>  
          <li>Search results</li>                                       
        </ul>
        <!--//crumbs-->
        
        <!--top right navigation-->
        <ul class="top-right-nav">
          <li><a href="#" title="Back to results">Back to results</a></li>
          <li><a href="#" title="Change search">Change search</a></li>
        </ul>
        <!--//top right navigation-->
      </nav>
      <!--//breadcrumbs-->
      
      <div class="row">
        <!--sidebar-->
        <aside class="one-fourth left-sidebar">
          <article class="widget refine-search-results">
            <h4>Refine search results</h4>
            
            <dl>
              <!--Price (per night)-->
              <dt>Price (per night)</dt>
              <dd>
             
              <form name="filterPrice" id="filterPrice">
                <div class="checkbox">
                <input type="checkbox" name="priceFilter[]" value="0-49">
                  <label for="ch1">0 - 49 $</label>
                </div>
                <div class="checkbox">
                    <input type="checkbox" name="priceFilter[]" value="50-99">
                  <label for="ch2">50 - 99 $</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" name="priceFilter[]" value="100-149">
                  <label for="ch3">100 -149 $</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" name="priceFilter[]" value="150-199">
                  <label for="ch4">150 - 199 $</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" name="priceFilter[]" value="200-100000000">
                  <label for="ch5">200 $ +</label>
                </div>
               </form>
              </dd>
              <!--//Price (per night)-->
              
              <!--Accommodation type-->
              <dt>Accommodation type</dt>
              <dd>
                <div class="checkbox">
                  <input type="checkbox" id="ch6" name="accommodation" />
                  <label for="ch6">Hotel</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch7" name="accommodation" />
                  <label for="ch7">Hostel</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch8" name="accommodation" />
                  <label for="ch8">Apart Hotel</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch9" name="accommodation" />
                  <label for="ch9">Guest House</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch30" name="accommodation" />
                  <label for="ch30">Apartment</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch31" name="accommodation" />
                  <label for="ch31">Bed &amp; Breakfast</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch32" name="accommodation" />
                  <label for="ch32">Residence</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch33" name="accommodation" />
                  <label for="ch33">Farm stay</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch34" name="accommodation" />
                  <label for="ch34">All-inclusive resort</label>
                </div>
              </dd>
              <!--//Accommodation type-->
              
              <!--Star rating-->
              <dt>Star rating</dt>
              <dd>
                <span class="stars-info">3 or more</span>
                <div id="star" data-rating="3">
                  
                </div><div id="star" data-rating="3" style="cursor: pointer; width: 110px;">
                <a href="une?query=<?php echo Input::get('query', '');?>"><img src="images/ico/star-rating-on.png" alt="1" a="1" title="bad"></a>&nbsp;<a href="deux?query=<?php echo Input::get('query', '');?>"><img src="images/ico/star-rating-on.png" alt="2" a="2" title="poor"></a>&nbsp;<a href="trois?query=<?php echo Input::get('query', '');?>"><img src="images/ico/star-rating-off.png" alt="3" a="3" title="regular"></a>&nbsp;<a href="quatre?query=<?php echo Input::get('query', '');?>"><img src="images/ico/star-rating-off.png" alt="4" a="4" title="good"></a>&nbsp;<a href="cinq?query=<?php echo Input::get('query', '');?>"><img src="images/ico/star-rating-off.png" href="#" alt="5" a="5" title="gorgeous"></a><input type="hidden" name="score" value="2"></div>
                <input type="hidden" value="<?php echo Input::get('query', '');?>"></input>
              </dd>
              <!--//Star rating-->
              
              <!--User rating-->
              <dt>User rating</dt>
              <dd>
                <div id="slider"></div>
                <span class="min">0</span><span class="max">10</span>
              </dd>
              <!--//User rating-->
              
              <!--Hotel facilities-->
              <dt>Hotel facilities</dt>
              <dd>
                <div class="checkbox">
                  <input type="checkbox" id="ch35" name="facilities" />
                  <label for="ch35">Wi-Fi</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch36" name="facilities" />
                  <label for="ch36">Parking</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch37" name="facilities" />
                  <label for="ch37">Airport Shuttle</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch38" name="facilities" />
                  <label for="ch38">Meeting / Banquet Facilities</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch39" name="facilities" />
                  <label for="ch39">Swimming pool</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch40" name="facilities" />
                  <label for="ch40">Restaurant</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch41" name="facilities" />
                  <label for="ch41">Fitness Centre</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch42" name="facilities" />
                  <label for="ch42">SPA &amp; Wellness Centre</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch43" name="facilities" />
                  <label for="ch43">Pets allowed</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch44" name="facilities" />
                  <label for="ch44">Lift</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch45" name="facilities" />
                  <label for="ch45">Air condition</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch46" name="facilities" />
                  <label for="ch46">Family rooms</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch47" name="facilities" />
                  <label for="ch47">Non - smoking rooms</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch48" name="facilities" />
                  <label for="ch48">Rooms/facilities for disabled guests</label>
                </div>
              </dd>
              <!--//Hotel facilities-->
              
              <!--Room facilites-->
              <dt>Room facilites</dt>
              <dd>
                <div class="checkbox">
                  <input type="checkbox" id="ch49" name="room-facilities" />
                  <label for="ch49">Bathroom</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch50" name="room-facilities" />
                  <label for="ch50">Cable TV</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch51" name="room-facilities" />
                  <label for="ch51">Air conditioning</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch52" name="room-facilities" />
                  <label for="ch52">Mini bar</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch53" name="room-facilities" />
                  <label for="ch53">Wi - Fi</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch54" name="room-facilities" />
                  <label for="ch54">Wheelchair - friendly room</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch55" name="room-facilities" />
                  <label for="ch55">Pay TV</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch56" name="room-facilities" />
                  <label for="ch56">Desk</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch57" name="room-facilities" />
                  <label for="ch57">Room safe</label>
                </div>
              </dd>
              <!--//Room facilites-->
              
              <!--Meal Board-->
              <dt>Meal Board</dt>
              <dd>
                <div class="checkbox">
                  <input type="checkbox" id="ch58" name="meal" />
                  <label for="ch58">No meal</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch59" name="meal" />
                  <label for="ch59">Bed &amp; Breakfast</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch60" name="meal" />
                  <label for="ch60">Half board</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch61" name="meal" />
                  <label for="ch61">Full board</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch62" name="meal" />
                  <label for="ch62">All - inclusive</label>
                </div>
              </dd>
              <!--//Meal Board-->
              
              <!--Accessibility options-->
              <dt>Accessibility options</dt>
              <dd>
                <div class="checkbox">
                  <input type="checkbox" id="ch63" name="accessibility" />
                  <label for="ch63">Accessible bathroom</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch64" name="accessibility" />
                  <label for="ch64">Accessible path of travel</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch65" name="accessibility" />
                  <label for="ch65">Handicapped parking</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch66" name="accessibility" />
                  <label for="ch66">In-room accessibility</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch67" name="accessibility" />
                  <label for="ch67">Roll-in shower</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch68" name="accessibility" />
                  <label for="ch68">Accessibility equipment for the deaf</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch69" name="accessibility" />
                  <label for="ch69">Braille or raised signage</label>
                </div>
              </dd>
              <!--//Accessibility options-->
              
              <!--Hotel theme-->
              <dt>Hotel theme</dt>
              <dd>
                <div class="checkbox">
                  <input type="checkbox" id="ch70" name="theme" />
                  <label for="ch70">Family Fun</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch71" name="theme" />
                  <label for="ch71">Adventure</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch72" name="theme" />
                  <label for="ch72">Beach &amp; Sun</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch73" name="theme" />
                  <label for="ch73">Casinos</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch74" name="theme" />
                  <label for="ch74">History &amp; Culture</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch75" name="theme" />
                  <label for="ch75">Clubbing</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch76" name="theme" />
                  <label for="ch76">Romance</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch77" name="theme" />
                  <label for="ch77">Shopping</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch78" name="theme" />
                  <label for="ch78">Skiing</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch79" name="theme" />
                  <label for="ch79">Wellness</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch80" name="theme" />
                  <label for="ch80">Eco &amp; Nature</label>
                </div>
              </dd>
              <!--//Hotel theme-->
              
              <!--Hotel chain-->
              <dt>Hotel chain</dt>
              <dd>
                <div class="checkbox">
                  <input type="checkbox" id="ch81" name="theme" />
                  <label for="ch81">Accor</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch82" name="theme" />
                  <label for="ch82">Hilton</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch83" name="theme" />
                  <label for="ch83">Lindner</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch84" name="theme" />
                  <label for="ch84">Marriott</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch85" name="theme" />
                  <label for="ch85">Tui</label>
                </div>
              </dd>
              <!--//Hotel chain-->
              
              <!--Payment options-->
              <dt>Payment options</dt>
              <dd>
                <div class="checkbox">
                  <input type="checkbox" id="ch86" name="theme" />
                  <label for="ch86">American Express</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch87" name="theme" />
                  <label for="ch87">Visa</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch88" name="theme" />
                  <label for="ch88">Euro/Mastercard</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" id="ch89" name="theme" />
                  <label for="ch89">Diners Club</label>
                </div>
              </dd>
              <!--//Payment options-->
            </dl>
          </article>
        </aside>
        <!--//sidebar-->
      
        <!--three-fourth content-->
    
        <div class="three-fourth">
          <div class="sort-by">
            <h3>Sort by</h3>
            <ul class="sort">
              <li>Popularity <a href="/Popularity" id="Popularity" title="ascending" class="ascending">ascending</a><a href="/popularity" id="popularityy" title="descending" class="descending" name="q">descending</a></li>
              <li>Price <a href="/min" id="asc" title="ascending" class="ascending">ascending</a><a href="/max" title="descending" id="desc" class="descending" name="q">descending</a></li>
              <li>Stars <a href="/star" id="star" title="ascending" class="ascending">ascending</a><a href="/stars" title="descending" id="stars" class="descending" name="q">descending</a></li>
              <li>Rating <a href="" title="ascending" class="ascending">ascending</a><a href="#" title="descending" class="descending">descending</a></li>
          

            </ul>
            
            <ul class="view-type">
              <li class="grid-view"><a href="#" title="grid view">grid view</a></li>
              <li class="list-view"><a href="#" title="list view">list view</a></li>
              <li class="location-view"><a href="#" title="location view">location view</a></li>
            </ul>
          </div>
          <div class="sort-by" style="display: none" id="sort">
       
          </div>
       {{ Form:: close() }}

          <div class="row deals  results">
          
              
       @include('presult')

          </div>
        </div>
        <!--//three-fourth content-->
      </div>
      <!--//main content-->
    </div>
  </main>
  <!--//main-->

@endsection

Open in new window



<form name="filterPrice" id="filterPrice">
                <div class="checkbox">
                <input type="checkbox" name="priceFilter[]" value="0-49">
                  <label for="ch1">0 - 49 $</label>
                </div>
                <div class="checkbox">
                    <input type="checkbox" name="priceFilter[]" value="50-99">
                  <label for="ch2">50 - 99 $</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" name="priceFilter[]" value="100-149">
                  <label for="ch3">100 -149 $</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" name="priceFilter[]" value="150-199">
                  <label for="ch4">150 - 199 $</label>
                </div>
                <div class="checkbox">
                  <input type="checkbox" name="priceFilter[]" value="200-100000000">
                  <label for="ch5">200 $ +</label>
                </div>
               </form>

Open in new window

pricefilter.png
pricefilter2.png
LaravelPHP* elasticsearch

Avatar of undefined
Last Comment
Soumaya Hachem

8/22/2022 - Mon