dimanche 20 mai 2018

Filter is not working when I click on pagination in laravel and mongo db

I have a filter functionality with pagination. Filter is working initially. When I click on pagination next button result is not showing based on filter.

eg: I have three countries in filter box. I chosen two then click on filter button then result is showing correct on first page but When I click on pagination next button all three countries result is showing not appending filter.

Thank you any help would be appreciated

Framework: laravel 5.5

Database: MongoDB

route.php

Route::match(['get', 'post'], '/search', 'SearchController@index')->name('search');

SearchController.php

public function index(SearchRequest $request)
    {
        $data = $request->all();
        $cabin = Cabin::select('_id', 'name', 'country', 'region', 'interior', 'sleeping_place', 'height', 'other_details', 'interior')
            ->where('is_delete', 0)
            ->where('other_cabin', "0");

        if(isset($request->cabinname)){
            $cabin->where('name', $request->cabinname);
        }

        if(isset($request->country)){
            $cabin->whereIn('country', $data['country']);
        }

        //dd($cabin->count());
        if(isset($request->region)){
            $cabin->whereIn('region', $data['region']);
        }

        $cabinSearchResult = $cabin->simplePaginate(5);

        return view('searchResult', ['cabinSearchResult' => $cabinSearchResult]);
    }

search.blade.php

<form action="" method="POST" class="navbar-form navbar-left" id="search-nav-home">

   

    <div class="form-group navbar-form navbar-left" id="prefetch">
         <input type="text" class="form-control-home typeahead" name="cabinname" id="cabinname" placeholder="Search Cabin">
    </div>

     <ul class="nav navbar-nav" id="filter-home">

         @if($services->country())
            <li class="dropdown">
               <!-- Dropdown in Filter -->
               <a href="#" class="dropdown-toggle dropdown-toggle-home" data-toggle="dropdown">Country <span class="caret"></span></a>
                <ul class="dropdown-menu dropdown-menu-home">
                   @foreach($services->country() as $land)
                     <li class="check-it-list-home"><input type="checkbox" class="check-it-home" name="country[]" value=""> </li>
                   @endforeach
                </ul>
               </li>
          @endif

          @if($services->regions())
             <li class="dropdown">

              <a href="#" class="dropdown-toggle dropdown-toggle-home" data-toggle="dropdown">Region<span class="caret"></span></a>
                 <ul class="dropdown-menu dropdown-menu-home drop-height">
                    @foreach($services->regions() as $region)
                    <li class="check-it-list-home"><input type="checkbox" name="region[]" value="" class="check-it-home"> 

                    </li>
                  @endforeach
                </ul>
               </li>
            @endif

          </ul>

          <div class="form-group navbar-form navbar-right" id="navbar-right-filter-home">
          <button type="submit" class="btn btn-default-home btn-filter-home">Filter Cabins</button>
  </div>
</form>

enter image description here



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2rVSev7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire