Php 使用Laravel 5和推进ORM分页
我正在尝试对每个页面进行分页6次,最大结果为 这是我在控制器中的代码:Php 使用Laravel 5和推进ORM分页,php,laravel,pagination,propel,Php,Laravel,Pagination,Propel,我正在尝试对每个页面进行分页6次,最大结果为 这是我在控制器中的代码: 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_vehicle
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'));
@foreach($paginator->getCollection()->all() as $pg)
{{ $pg->ImagePath }} {{--ImagePath is the php name of a table column--}}
@endforeach
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.
这是我在*.blade.php中的代码:
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'));
@foreach($paginator->getCollection()->all() as $pg)
{{ $pg->ImagePath }} {{--ImagePath is the php name of a table column--}}
@endforeach
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.
但我得到了一个错误:试图获取非对象的属性
任何建议都会有帮助
过滤方法:
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'));
@foreach($paginator->getCollection()->all() as $pg)
{{ $pg->ImagePath }} {{--ImagePath is the php name of a table column--}}
@endforeach
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.
在这种情况下,我没有使用推进,而是使用了照明\Support\Facades\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);
如果任何人找到了通过推进的方法,请发布答案。无论如何,谢谢大家,感谢你们的帮助…请添加导致错误的信息使用
@foreach($paginator->getCollection()as$pg)
而不是@foreach($paginator->getCollection()->all()as$pg)
我想从这行{{{$pg->ImagePath}}
开始。如果我的代码是{{$pg->getImagePath()}
它会给我错误:调用数组上的成员函数getImagePath()。我尝试了@foreach($paginator->getCollection()as$pg)
。但是给出了保存错误。当我尝试{{dd($pg)}
时,它返回array:1[▼ 1790921346=>0]