Reputation: 21
I'm working on Laravel project that has two models: Offer
belongsTo 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:
$category = Category::whereId($category_id)->with('offers')->first()->paginate(10);
and I get this error:
Undefined property: Illuminate\Pagination\Paginator::$offers
I've solved it by replacing the second code with this:
$category = Category::find($category_id);
$offers = $category->offers()->paginate(10);
Upvotes: 1
Views: 1353
Reputation: 21
replace the second code with this:
$category = Category::find($category_id);
$offers = $category->offers()->paginate(10);
Upvotes: 1