Question

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 

UPDATE:

I've solved it by replacing the second code with this:

$category = Category::find($category_id);
$offers = $category->offers()->paginate(10);
Was it helpful?

Solution

replace the second code with this:

$category = Category::find($category_id);
$offers = $category->offers()->paginate(10);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top