[Vuejs]-Laravel Invoice & InvoiceItems โ€“ How to Update?

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);

Leave a comment