Support the ongoing development of Laravel.io →
Requests Database Eloquent

So, I have a situation where users can add posts to a forum and then comment on those posts.

What I want to achieve here is pulling in all forum posts within the past 24 hours, but I only want the posts that have the most messages (let's say max 5 records). I would like to order by those message counts as well.

I have relationships set up between the the two models already.

ForumPosts hasMany('Comments');

Comments belongsTo('ForumPosts');

Any thoughts as to what I could do?

Last updated 3 years ago.
0

Any takers?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ayyobro ayyobro Joined 25 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.