Я использую Laravel 5.7 для создания API, который обеспечивает ответ JSON.Я создаю следующий JSON, но он требует некоторых изменений.Мой JSON в настоящее время не содержит некоторых массивов некоторых столбцов из таблицы, но согласно требованию разработчика мне нужны эти массивы для некоторых столбцов.Ожидаемый JSON, как показано ниже.Требуется решение.
Контроллер:
public function displayAllBookingList(Request $req)
{
$user_id=$req->input('user_id');
$api_token=$req->input('api_token');
$ground_area=$req->input('ground_area');
$query_get_user_details=DB::table('table_registration')
->select('table_registration.*')
->where('user_id',$user_id)
->first();
if($query_get_user_details==NULL)
{
return response()->json(['success' => '0', 'message' =>'Error']);
}
else if($query_get_user_details->api_token==$api_token)
{
$get_ground_list=DB::table('table_ground')
->select('table_ground.*')
->where('ground_area',$ground_area)
->get();
return response()->json(['success' => '1','data' =>$get_ground_list]);
}
else
{
return response()->json(['success' => '0', 'message' =>'Oops Something Wrong']);
}
}
Текущий ответ JSON:
{
"success": "1",
"data": [
{
"id": 1,
"ground_id": 1,
"ground_name": "hockey stadium",
"ground_area": "kolhapur",
"booked_status": 0,
"time": "6.00 am to 8.00pm",
"ground_pics": "http://192.168.1.132:8000/images/ground_pic/1.jpg,http://192.168.1.132:8000/images/ground_pic/2.jpg",
"available_sports": "hockey,cricket",
"ground_amenities": "parking,toilet,water",
"ground_rating": 4.5,
"ground_address": "MSEB Ring Road, Datta Colony, Kolhapur, Maharashtra, 416008",
"longitude": "85.501980",
"latitude": "23.624420",
"updated_at": "0000-00-00 00:00:00",
"created_at": "0000-00-00 00:00:00"
}
]
}
Требуемый ответ JSON:
{
"success": "1",
"data": [
{
"id": 1,
"ground_id": 1,
"ground_name": "hockey stadium",
"ground_area": "kolhapur",
"booked_status": 0,
"time": "6.00 am to 8.00pm",
"ground_pics": ["http://192.168.1.132:8000/images/ground_pic/1.jpg,http://192.168.1.132:8000/images/ground_pic/2.jpg"],
"available_sports": ["hockey,cricket"],
"ground_amenities": ["parking,toilet,water"],
"ground_rating": 4.5,
"ground_address": [
"MSEB Ring Road, Datta Colony, Kolhapur, Maharashtra, 416008"
],
"longitude": "85.501980",
"latitude": "23.624420",
"updated_at": "0000-00-00 00:00:00",
"created_at": "0000-00-00 00:00:00"
}
]
}