0๐
โ
First, deleted child records:
$ticketInvoice->ticketInvoiceItems()->delete();
Then store the new ones:
$ticketInvoiceItems = collect();
foreach($request['ticketInvoiceItems'] as $invoiceItem) {
$ticketInvoiceItems->push(new TicketInvoiceItems ([
'passenger_name' => $invoiceItem ['passenger_name'],
'ticket_no' => $invoiceItem ['ticket_no'],
'fares' => $invoiceItem ['fares'],
'sub_total' => $invoiceItem ['sub_total']
]));
}
$ticketInvoice->ticketInvoiceItems()->saveMany($ticketInvoiceItems);
Source:stackexchange.com