I am using Laravel 7.26 and I have two tables, categories
and posts
they share the following relationship:
class Post
public function categories(){
return $this->belongsToMany('App\Category', 'post_category');
}
and
class Category
public function posts(){
return $this->belongsToMany('App\Post', 'post_category');
}
How can I order categories by the count of the posts belonging to them for the past 24 hours and show the count of the posts from the past 24 hours belonging to that category?