Я хочу нумерацию страниц с фильтром ajax, но с двумя разными контроллерами - PullRequest
0 голосов
/ 18 июня 2019

Я хочу отфильтровать некоторые данные, вызвав метод ajax. Страница с отображением данных содержит нумерацию страниц, которая разбита на страницы контроллером. Однако мои данные AJAX поступают с другого контроллера, что создает проблему разбивки отфильтрованных данных на страницы.

публичная функция HarvesterFilter ($ page = 0) {

    $harvesters = DB::table('harvester')
                        ->select('harvester.id as havId','brand.id as brandId','brand.name as brandName','brand.slug as brandSlug','harvester.slug as havSlug','model_name','harvester.image as havImage','power_Source','cutterbar','epower','hprice','harvester.crop')
                        ->join('brand','brand.id','=','harvester.brand')
                        ->where('status',1)
                        ->get();

    if($this->request->ajax()){

                        if($this->request->has('brands') && $this->request->has('brands') !== null)
                        {
                            $brands = explode(",",$this->request->brands);
                            $harvesters = $harvesters->whereIn('harvester.brand',$brands);
                        }   

                        if($this->request->has('cuttingwidth') && $this->request->has('cuttingwidth') !== null)
                        {
                            $cuttingwidth = explode(",",$this->request->cuttingwidth);

                             if(count($cuttingwidth) == 1)
                             {
                                if($cuttingwidth[0] == 'lessthan10')
                                    $harvesters = $harvesters->whereBetween('cutterbar',[1,10]);
                                elseif($cuttingwidth[0] == 'greternthan10')
                                    $harvesters = $harvesters->whereBetween('cutterbar',[11,20]);
                            }
                            elseif(count($cuttingwidth) > 1)
                            {
                                    $harvesters = $harvesters->whereBetween('cutterbar',[1,20]);
                            }
                        }

                        if($this->request->has('power') && $this->request->has('power') !== null)
                        {
                            $self = explode(",",$this->request->power);
                            $harvesters = $harvesters->whereIn('power_Source',$self);

                        }
                        $harvesters = $harvesters->paginate(10, ['*'], 'page', $page);
                        return  view('pages.harvesterGrid')->with('harvesters',$harvesters);
        }

     else{
                        return  view('layouts.harvesterGrid')->with('harvesters',$harvesters);
         }
}

<div class="col-md-9 col-sm-12 col-xs-12">
            @if(Request::has('brands') || Request::has('cuttingwidth') || Request::has('power'))
               {{$harvesters->appends(['brands' => Request()->brands ,'cuttingwidth' =>Request()->cuttingwidth,'power' => Request()->power,])->links()}}
            @else
                {{$harvesters->links()}}
            @endif
        </div>
...