Php laravel中带子阵的搜索返回数组

Php laravel中带子阵的搜索返回数组,php,mysql,laravel,Php,Mysql,Laravel,你好社区在拉雷维尔我正在做一个搜索,一个数组列表返回我,这是完美的。我想返回一个带有列表的子数组,如何使用select完成?在laravel中使用db::table DB::table("campania_post AS pt") ->join("campania AS c","c.id","=","pt.campania_id") ->where("c.manager_id", "=", $user->id)

你好社区在拉雷维尔我正在做一个搜索,一个数组列表返回我,这是完美的。我想返回一个带有列表的子数组,如何使用select完成?在laravel中使用db::table

DB::table("campania_post AS pt")
                ->join("campania AS c","c.id","=","pt.campania_id")
                ->where("c.manager_id", "=", $user->id)
                ->leftJoin("files AS f","f.id","=","c.avatar")
                ->where("pt.status", "=", 0)
                ->select("c.id", "c.nombre", "c.avatar", "f.name", "c.created_at", 'f.id as file_picture')
                ->groupby("c.id")
                ->get();

对于查询生成器: 您可以使用
GROUP\u CONCAT
创建字符串。然后对结果使用
map
,将其转换为数组

$data=DB::table(“campania_post AS pt”)
->加入(“坎帕尼亚为c”,“c.id”,“=”,“pt.campania_id”)
->其中(“c.manager\u id”,“=”,$user->id)
->leftJoin(“文件名为f”、“f.id”、“=”、“c.avatar”)
->其中(“pt.status”、“=”、0)
->选择(“c.id”、“c.nombre”、“c.avatar”、“f.name”、“c.created_at”、“DB::raw”(“GROUP_CONCAT(f.id)”,“)作为文件图片”))
->groupby(“c.id”)
->不同的()
->get();
$data->map(函数($q){
$q->file\u picture=分解(“,”,$q->file\u picture);
返回$q;
});

就这些。

谢谢,使用->distinct()
$data->map(function ($singleData) {
$singleData['img'] = ['Add your sub array'];
return $singleData; });