i am saving data to booking table, and i want to add data to participant table as many times as total_pax are there, the first one in partiipant will be created by my code , now i want to create blank entries for remaining pax inn participant table on basis of total_pax which are in booking
Here is the booking object
{"booking":{
"package_id":4,
"user_id":1,
"package_name":"masti maza",
"first_name":"shubham",
"last_name":"pradhan",
"email":"[email protected]",
"total_pax":"5",
}
Now i create Booking
$booking = $request->booking;
$book = Booking::create($booking);
Thereafter i created a single entry in participant table
$book->Participants()->create([
'booking_id' => $book->id,
'first_name' => $booking['first_name'],
'last_name' => $booking['last_name'],
'email' => $booking['email']
]);
But i also want to create 4 more entries as total_pax in booking request is 5 , one is created ,
but i want to create 4 more entries in participant that will have only booking_id, because others column are nullable
2
Answers
Can you loop through the
total_pax
object like so?use
createMany
instead ofcreate
and pass multiple modal objects on it