简体   繁体   English

Laravel 4雄辩的分页相关模型

[英]Laravel 4 Eloquent paginate related model

I'm working on Laravel project that has two models: Offer belongsTo Category . 我正在研究具有两个模型的Laravel项目: Offer BetweenTo Category

It's easy to paginate the results when I'm retrieving all records: 在检索所有记录时,很容易对结果进行分页:

$offers = Offer::paginate(10);

But when I'm trying to just retrieve Offers that has specific Category , It just do not work: 但是,当我试图只是检索Offers具有特定Category ,它只是不工作:

$category = Category::whereId($category_id)->with('offers')->first()->paginate(10);

and I get this error: 我得到这个错误:

 Undefined property: Illuminate\Pagination\Paginator::$offers 

UPDATE: 更新:

I've solved it by replacing the second code with this: 我已经通过替换第二个代码来解决了这个问题:

$category = Category::find($category_id);
$offers = $category->offers()->paginate(10);

replace the second code with this: 将第二个代码替换为:

$category = Category::find($category_id);
$offers = $category->offers()->paginate(10);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM