Я пытаюсь опубликовать содержимое бронирования с массивом пассажиров, но оно всегда возвращает неверный аргумент, указанный для foreach (). В чем проблема?
public function postBooking(Request $request)
{
$user = JWTAuth::parseToken()->authenticate();
$booking = Booking::create([
'service_name' => $request->get('service_name'),
'service_package' => $request->get('service_package'),
'travel_date' => $request->get('travel_date'),
'travel_day' => $request->get('travel_day'),
'travel_time' => $request->get('travel_time'),
'remark' => $request->get('remark'),
'booking_name' => $request->get('booking_name'),
'mobile_number' => $request->get('mobile_number'),
'email' => $request->get('email'),
'nationality' => $request->get('nationality'),
'user_id' => $user->user_id,
]);
$passengers = $request['passengers'];
if(is_array($passengers))
{
foreach($passengers as $passenger)
{
$passenger = Passenger::create([
'passenger_name' => $passenger['passenger_name'],
'ic_passport' => $passenger['ic_passport'],
'booking_id' => $booking->booking_id
]);
}
}
$response = (object)[];
$response->booking = $booking->makeHidden('users');
$response->passengers = $passengers;
return response()->json(['data'=>$response, 'status'=>'ok']);
}