user3447630
user3447630

Reputation: 21

Laravel 4 Eloquent paginate related model

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);

Upvotes: 1

Views: 1353

Answers (1)

user3447630
user3447630

Reputation: 21

replace the second code with this:

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

Upvotes: 1

Related Questions