2015-07-12 181 views
2

我正在嘗試將分頁6最大結果分配給每個頁面。Paginate使用Laravel 5和Propel ORM

這是我在控制器代碼:

public function brand_new(Request $request) 
    { 
$current_page = $request->get('page', 1); 
$find_vehicles = $this->filterAll();//retrieving all the vehicles by calling a method 
     $total = $find_vehicles->count(); 
     $paginator = new LengthAwarePaginator($find_vehicles, $total, 6, $current_page); 
     $paginator->setPath($request->getBasePath()); 
return view('pages.massSearch',compact('paginator')); 

這是我在* .blade.php代碼:

@foreach($paginator->getCollection()->all() as $pg) 
    {{ $pg->ImagePath }} {{--ImagePath is the php name of a table column--}} 
    @endforeach 

但我發現了錯誤:試圖獲得非物件的財產

任何建議,將有助於...

filterAll方法:

public function filterAll($val) 
    { 
     $filter_avl = VehicleQuery::create() 
      ->filterByAvailability(true) 
      ->find(); 
     $filter_modelAvl = VehicleQuery::create() 
      ->useVModelQuery() 
      ->filterByAvailability(true) 
      ->endUse() 
      ->find(); 
     $filter_bndAvl = VehicleQuery::create() 
      ->useVBrandQuery() 
      ->filterByAvailability(true) 
      ->endUse() 
      ->find(); 

     $filter_cStatus = VehicleQuery::create() 
      ->useCurrrentStatusQuery() 
      ->endUse() 
      ->find(); 
     $filter_mode = VehicleQuery::create() 
      ->useVehicleModeQuery() 
      ->filterByModeName($val) 
      ->endUse() 
      ->find(); 

     $find_vehicles = VehicleImagesQuery::create() 
      ->joinWith('VehicleImages.Vehicle') 
      ->joinWith('Vehicle.VModel') 
      ->joinWith('Vehicle.VBrand') 
      ->joinWith('Vehicle.CurrrentStatus') 
      ->joinWith('Vehicle.VehicleMode') 
      ->filterByVehicle($filter_avl) 
      ->filterByVehicle($filter_modelAvl) 
      ->filterByVehicle($filter_bndAvl) 
      ->filterByVehicle($filter_cStatus) 
      ->filterByVehicle($filter_mode) 
      ->find(); 
     return $find_vehicles; 
    }//no errors with this code retrieve data perfectly.. Pagination part is the problem. 
+0

請添加關於哪一行導致錯誤的信息 – canton7

+0

使用'@foreach($ paginator-> getCollection()作爲$ pg)'而不是'@foreach ($ paginator-> getCollection() - > all()as $ pg)' –

+0

我想形成'{{$ pg-> ImagePath}}'這一行。如果我編碼爲'{{$ pg-> getImagePath()}}'它給了我錯誤:調用數組上的成員函數getImagePath()。 – PereraSH

回答

1

而不是使用推動我以前照亮的\ Support \外立面\ DB這種情況

$find_vehicles = DB::table('vehicle_images') 
      ->join('vehicle', 'vehicle_images.vehicle_id', '=', 'vehicle.id') 
      ->join('V_model', function ($join1) { 
       $join1->on('vehicle.V_model_id', '=', 'V_model.id')->where('V_model.availability', '=', true); 
      }) 
      ->join('V_brand', function ($join2) { 
       $join2->on('vehicle.V_brand_id', '=', 'V_brand.id')->where('V_brand.availability', '=', true); 
      }) 
      ->join('Currrent_status', 'vehicle.Currrent_status_id', '=', 'Currrent_status.id') 
      ->join('vehicle_transmission', 'vehicle.vehicle_transmission_id', '=', 'vehicle_transmission.id') 
      ->join('vehicle_mode', function ($join3) use($val) { 
       $join3->on('vehicle.vehicle_mode_id', '=', 'vehicle_mode.id')->where('vehicle_mode.mode_name', '=',$val); 
      }) 
      ->paginate(6); 

如果有任何一個找到方法與推動請發佈答案..任何方式謝謝你的人,感謝你的幫助...