Код: Выделить всё
class Post extends Model
{
// @property int $id
// @property string $title
// @property string $user_id
public function comments()
{
return $this->hasMany(Comment::class);
}
}
class Comment extends Model
{
// @property int $id
// @property int $post_id
// @property int $user_id (author ids + guests ids)
// @property string $content
public function post()
{
return $this->belongsTo(Post::class);
}
}
[img]https:/ /i.sstatic.net/H3bGXj9O.jpg[/img]
Мне нужно получить список сообщений с количеством загруженных комментариев для автора и гостей, поэтому мой вопрос:
Как я могу получить количество комментариев автора (author_comments_count = 2) и количество комментариев гостей (guests_comments_count = 3) с помощью withCount()
Спасибо за продвигаться
Подробнее здесь: https://stackoverflow.com/questions/784 ... ount-query
Мобильная версия