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 关注
- 159 浏览
添加回答
举报