我有分页过滤功能。过滤器开始工作。当我单击分页时,下一个按钮的结果不会根据过滤器显示。
我在过滤箱里有三个国家。我选择了两个,然后点击过滤按钮,结果在第一页显示正确,但当我点击分页下一个按钮,所有三个国家的结果显示不附加过滤。
谢谢,有什么帮助我会感激的
框架:Laravel 5.5
数据库:
MongoDB
路由.php
Route::match(['get', 'post'], '/search', 'SearchController@index')->name('search');
搜索控制器.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]);
}
搜索.blade.php
<form action="{{ route('search') }}" method="POST" class="navbar-form navbar-left" id="search-nav-home">
{{ csrf_field() }}
<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="{{ $land->name }}"> {{ $land->name }}</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="{{ $region->name }}" class="check-it-home"> {{ $region->name }}
</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>