Php Laravel:如何使用查询生成器获取列中的对象

Php Laravel:如何使用查询生成器获取列中的对象,php,laravel,laravel-7,Php,Laravel,Laravel 7,我想显示我在下面描述的数据类型,但我不知道关键字 现在,这是我的数据: 这就是我想要的结果: 这是我的控制器: $data = DB::table('tr_doctor_schedules as sch') ->select('sch.id as schedule_id','doctor_name','hospital_name','estimated_practice_time','day','from_time','until_time') ->join('m

我想显示我在下面描述的数据类型,但我不知道关键字

现在,这是我的数据:

这就是我想要的结果:

这是我的控制器:

$data = DB::table('tr_doctor_schedules as sch')
    ->select('sch.id as schedule_id','doctor_name','hospital_name','estimated_practice_time','day','from_time','until_time')
    ->join('mst_hospitals as hos', 'hos.id', '=', 'sch.hospital_id')
    ->join('mst_doctors as doc', 'doc.id', '=', 'sch.doctor_id')
    ->join('tr_doctor_schedule_details as dtl', 'dtl.doctor_schedule_id', '=', 'sch.id')
    ->where('sch.hospital_id', $hosId)
    ->where('sch.doctor_id', $docId)
    ->first();

if ($data) {
    return response()->json([
        'success' => true,
        'message' =>'success',
        'data'    => $data
    ], 200);
} else {
    return response()->json([
        'success' => false,
        'message' => 'Data not found.',
    ], 400);
}
谢谢你试试这个

   $data = DB::table('tr_doctor_schedules as sch')
        ->selectRaw('sch.id as schedule_id,doctor_name,hospital_name,estimated_practice_time,GROUP_CONCAT(day) as day,from_time,until_time')
        ->join('mst_hospitals as hos', 'hos.id', '=', 'sch.hospital_id')
        ->join('mst_doctors as doc', 'doc.id', '=', 'sch.doctor_id')
        ->join('tr_doctor_schedule_details as dtl', 'dtl.doctor_schedule_id', '=', 'sch.id')
        ->where('sch.hospital_id', $hosId)
        ->where('sch.doctor_id', $docId)
        ->groupBy('sch.id')
        ->first();

似乎您需要在day Column中使用
group_concat
为什么from时间是8而不是9,Toil时间是18而不是19,这有逻辑吗?从第9行到结尾,没有逻辑,但我只是添加了大量的响应toothanks,问题解决了。在postgres中我使用了array_agg()是的。。我的荣幸