webfuelcode's avatar

Paginate for posts under category

Trying to show the latest posts with pagination.

$subposts = Category::with(['posts', 'children.posts'])->where('id', $category->id)->first();

Tried get(), latest() but sometimes it says property does not found and sometimes collection error.

I have a page designed for subcategory and post list on two columns.

0 likes
1 reply
Mirlan Bekturov's avatar

Try get posts by category relation. For example:

$subposts = Posts::where('category_id', $category->id)->paginate(10);

Please or to participate in this conversation.