我如何使用laravel获取所需的json格式?

时间:2019-06-27 11:19:05

标签: json laravel

我正在使用laravel创建api并生成json,但我需要下面给出的json。 business_table的business_pic字段包含多个以分隔的图像,我想在上述给定的json中获取。

控制器:

$get_booking_details= DB::table('table_booking_list')
            ->join('table_booking_details', 'table_booking_list.booking_id', '=', 'table_booking_details.booking_id')
            ->select('table_booking_details.*')
            ->where('table_booking_details.booking_id',$booking_id)
            ->get();

      return response()->json(['success' => '1','data' =>$get_booking_details]);

 json that obtained from my controller:


   {
        "success": "1",
        "data": [
            {
                "id": 1,
                "booking_list_id": 1,
                "booking_id": 1,
                "booking_pics": "http://192.168.1.132:8000/images/ground_pic/1.jpg,http://192.168.1.132:8000/images/ground_pic/2.jpg",
                "updated_at": "2019-06-27 12:46:40",
                "created_at": "0000-00-00 00:00:00"
            }
        ]
    }

我想要的json:

{
    "success": "1",
    "data": [{
        "id": 1,
        "booking_list_id": 1,
        "booking_id": 1,
        "booking_pics": [{
                "image": "http://192.168.1.132:8000/images/ground_pic/1.jpg"
            },
            {
                "image": "http://192.168.1.132:8000/images/ground_pic/2.jpg"
            }
        ],

        "updated_at": "2019-06-26 16:42:02",
        "created_at": "0000-00-00 00:00:00"
    }]
}

0 个答案:

没有答案