我有三个使用此表的表,我正在获取json,但是我的json有一些更改。 Booking_details表中包含了sports_id,它是内爆的,因此文件中包含多个以逗号分隔的运动ID。这是从运动详情表中获取的。我无法详细解释plz检查我的json以及如何获取所需的json?
1)booking_list ID预订ID预订名称已更新创建时间(at 1 1体育--)
2)booking_details id预订_详细信息_id预订_id预订_区域体育_id (1 1 1浦那1,2)
3)sport_details id sport_id sport_name sport_image (1 1曲棍球- 2 2板球---)
控制器:
$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();
$temp=$available_sports=$booking_amenities=array();
foreach($get_booking_details as $item)
{
foreach(explode(",",$item->available_sports) as $items)
{
$item_arr=array('sports'=>$items);
$item_obj=(object)$item_arr;
array_push($available_sports,$item_obj);
}
$item->available_sports=$available_sports;
}
return response()->json(['success' => '1','data' =>$get_booking_details]);
我的输出json为:
{
"success": "1",
"data": [{
"id": 1,
"booking_list_id": 1,
"booking_id": 1,
"booking_name": "sports",
"booking_area": "pune",
"available_sports": [{
"sports": "1"
},
{
"sports": "2"
}
],
"updated_at": "2019-06-30 16:41:41",
"created_at": "0000-00-00 00:00:00"
}]
}
必需的json:
{
"success": "1",
"data": [{
"id": 1,
"booking_list_id": 1,
"booking_id": 1,
"booking_name": "sports",
"booking_area": "pune",
"available_sports": [{
"sports": "hockey",
"sport_image": ".."
},
{
"sports": "cricket",
"sport_image": ".."
}
],
"updated_at": "2019-06-30 16:41:41",
"created_at": "0000-00-00 00:00:00"
}]
}