我对查询感到困惑。我有一个带有{type}字段的帖子表.type字段有不同的值。现在的要求是,我想获取特定类型的帖子使用groupBy {Date}。
Collection {#832 ▼
#items: array:5 [▼
0 => Post {#833 ▶}
1 => Post {#834 ▶}
2 => Post {#835 ▶}
3 => Post {#836 ▶}
4 => Post {#837 ▼
Post: array:5 [▼
0 => Post {#833 ▶}
1 => Post {#834 ▶}
2 => Post {#835 ▶}
3 => Post {#836 ▶}
]
}
]
}
第一个数组中的第四个键是groupBy。 我希望你能理解我的要求 在此先感谢
答案 0 :(得分:0)
尝试类似:
$type = "example"; //whatever a valid value for type would by, based on your code.
Post::where('type', $type)->groupBy('date')->get();
将where()
放在groupBy()
之前,您可以对结果进行过滤。