我有一些查询需要一段时间,因为集合很大。
我现在直接通过 Laravel 查询生成器在没有活动记录的情况下进行操作。
将两个表连接在一起时,表 B 中的字段将合并到表 A 中的结果中。
是否可以将该数据嵌套在子对象或数组中?
例如
\DB::table('posts')
->select('posts.id', 'posts.title', 'comments.name', 'comments.id')
->where('posts.status', '=', 'PUBLIC')
->leftJoin('comments', 'posts.comment_id', '=', 'comments.id')
->get();
返回类似:
{
id: 123,
title: 'My post',
name: 'Comment name',
// ...
}
我想在哪里:
{
id: 123,
title: 'My post',
comment {
name: 'Comment name',
// ...
}
// ...
}