eyesberg
eyesberg
FFilament
Created by eyesberg on 10/28/2024 in #❓┊help
Create Repeater Data on handleRecordCreation
Is there a way to create datas from Repeater on handleRecordCreation. Here's the case, I need to create a BuyingInvoice and BuyingInvoiceItem (it comes from the Repeater so there'll be some BuyingInvoiceItem ) on handleRecordCreation. Because I need to the id from the created BuyingInvoice and BuyingInvoiceItem s to create a StockUpdate that have the foreignId of BuyingInvoice and BuyingInvoiceItems Here's one of the BuyingInvoiceItem's data array
"item_id" => "1",
"price" => 10000,
"quantity" => "36",
"subtotal" => 360000,
];
"item_id" => "1",
"price" => 10000,
"quantity" => "36",
"subtotal" => 360000,
];
before I post this, I already try this way on the handleRecordCreation, well it works! BUT after the handleRecordCreation finished, it creates another BuyingInvoiceItems that comes from the Repeater
foreach ($buyingInvoiceItems as $buyingInvoiceItem) {
$buyingInvoice->buyingInvoiceItems()->create([
'item_id' => $buyingInvoiceItem['item_id'],
'quantity' => $buyingInvoiceItem['quantity'],
'price' => $buyingInvoiceItem['price'],
'subtotal' => $buyingInvoiceItem['subtotal'],
]);
foreach ($buyingInvoiceItems as $buyingInvoiceItem) {
$buyingInvoice->buyingInvoiceItems()->create([
'item_id' => $buyingInvoiceItem['item_id'],
'quantity' => $buyingInvoiceItem['quantity'],
'price' => $buyingInvoiceItem['price'],
'subtotal' => $buyingInvoiceItem['subtotal'],
]);
so the result on the Database there are two BuyingInvoiceItems with the exact same data just ith the different Id (because the data from Repeater created twice, the first one is on the handleRecordCreation that I made myself, and the other one is from outside the handleRecordCreation I guess?) How to solve this so that the BuyingInvoiceItems didnt duplicated
1 replies