你好,我有与关系的帖子模型:
public function category()
{
return $this->belongsTo(category::class);
}
我需要在类别的每个标签上显示帖子。为此,我需要使用groupBy。当我这样做时:
$posts = Post::with('category')->groupBy('category.title')->get();
我收到错误:
Column not found: 1054 Unknown column 'category.title'.
为什么?如何使用类别标题键返回我的帖子?
$posts = Post::with('category')->get()->groupBy('category.title')->toArray();