Hi!
Filter products work is fine, and pagination work is fine too.
But when i first filter data and then try paginate filter droped
Filter data and paginate i need see url as
?brands%5B%5D=2&page=2
but when i paginate filtered data i have url
?page=2
Filter is gone
HTML
@section('filters')
<div class="sidebar-module-container">
<h3 class="section-title">Сортировать</h3>
<div class="sidebar-filter">
<div class="sidebar-widget outer-bottom-xs wow fadeInUp">
<div class="widget-header">
<h4 class="widget-title">Производители</h4>
</div>
<div class="sidebar-widget-body m-t-20">
<form action="" method="GET" accept-charset="utf-8">
<ul>
<?php $brands = Input::has('brands') ? Input::get('brands'): [] ; ?>
@foreach($producers->producerToKind as $producer)
<li><input type="checkbox" name="brands[]" value="{{ $producer->id }}" {{ in_array($producer->id, $brands) ? 'checked' : '' }}> {{ $producer->title }}</li>
@endforeach
</ul>
<button type="submit">Sort</button>
</div>
</div>
</div>
</div>
@stopassola
@section('content')
@include('pagination', ['paginator' => $products])
@foreach($products as $data)
{{ $data->title }}
{{ $data->description }}
@endforeach
@stop
CONTROLLER
public function index($kind, Request $request)
{
$kind = Categories::where('path', $kind)->first();
if($kind == NULL or $kind->type == 'producer' or $kind == FALSE)
{
return abort(404);
} else {
$producers = Categories::find($kind->id);
// $products = Products::where('kind_id', $kind->id)->orderBy('product_order', 'desc')->paginate(12);
$brands = Input::has('brands') ? Input::get('brands') : null;
$products = Products::where('kind_id', $kind->id)->where(function($query){
$brands = Input::has('brands') ? Input::get('brands') : null;
if(isset($brands)){
foreach ($brands as $brand) {
$query->orWhere('producer_id', '=', $brand);
}
}
})->orderBy('product_order', 'desc')->paginate(12);
if(!empty($products->currentPage()))
{
$pageNumber = $products->currentPage() == 1 ? '' : $products->currentPage();
}
return view('categories.index', compact(['products']))
->with('category', $kind)
->with('producers', $producers)
->with('pageNumber', $pageNumber)
->withInput(Input::all());
}
}
MODEL
class Products extends Model
{
public $timestamps = false;
protected $table = 'products';
protected $fillable = ['title', 'path', 'preview', 'short_description', 'price', 'usd', 'parent_type', 'producer_id'];
public function value()
{
return $this->hasOne('App\Values', 'product_id');
}
public function producer()
{
return $this->belongsTo('App\Categories', 'producer_id');
}
public function kind()
{
return $this->belongsTo('App\Categories', 'kind_id');
}
public function images()
{
return $this->hasMany('App\Images', 'product_id');
}
}
Please help i need create filters as woocomerce with paginate! Maybe some one have a good tutorial or help with my code?