php - Laravel 4 Eloquent paginate related model -


i'm working on laravel project has 2 models: offer belongsto category.

it's easy paginate results when i'm retrieving records:

$offers = offer::paginate(10); 

but when i'm trying retrieve offers has specific category, not work:

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

and error:

 undefined property: illuminate\pagination\paginator::$offers  

update:

i've solved replacing second code this:

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

replace second code this:

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

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -