Код: Выделить всё
[
'post_1' => [
'comments' => [
'comment_1' => 'trst comment',
'comment_2' => 'trst comment',
'comment_3' => 'trst comment',
],
],
'post_2' => [
'comments' => [
'comment_1' => 'trst comment',
'comment_2' => 'trst comment',
'comment_3' => 'trst comment',
],
],
'post_3' => [
'comments' => [
'comment_1' => 'trst comment',
'comment_2' => 'trst comment',
'comment_3' => 'trst comment',
],
],
]
В laravel можно получить количество отношений hasMany одной строки
Код: Выделить всё
Post::first()->comments()-count()
Код: Выделить всё
Post::get()->comments()-count()
Подробнее здесь: https://stackoverflow.com/questions/576 ... otal-posts