2 回答

TA貢獻1876條經驗 獲得超5個贊
您的數據來自表單的數組。因此,循環遍歷數組并在每次迭代中插入值。示例方法:
public function addBooking(Request $request)
{
$booking = Booking::create([
'mobile_no' => $request->mobile_no,
'email' => $request->email,
//add if you want you add any more column
]);
foreach ($request->title as $key => $value) {
BookingDetails::create([
'booking_id' => $booking_id,
'title' => $request->title[$key],
'fname' => $request->fname[$key],
'lname' => $request->lname[$key],
//other columns
]);
}
return->back();
}

TA貢獻1830條經驗 獲得超3個贊
公共函數 addBooking(Request $request){
$booking = Booking::create([
'mobile_no' => $request->mobile_no,
'email' => $request->email,
//add if you want you add any more column
]);
$bookings=[];
foreach($request->title as $key => $value){
array_push(bookings,[
'booking_id' => $booking_id,
'title' => $request->title[$key],
'fname' => $request->fname[$key],
'lname' => $request->lname[$key]
]);
}
BookingDetails::insert($bookings);
return->back();
}
- 2 回答
- 0 關注
- 181 瀏覽
添加回答
舉報