Custom Livewire component that sets a new item to the repeater component inside the resource's form
I have an OrderResource form. Inside that form I use the Repeater component to handle the orderlines entries for the Order Model. Each Orderline item inside the Repeater has a SELECT Input for product_id, quantity, overwrite prices inputs etc.
I have made another custom component called Scanner that uses a scanner library for qrcodes. I have made all the logic to find a product and now I am stuck on how to interacts with the form's state and specifically with the repeaters state to set a new entry
class Scanner extends Component
{
public bool $scannerOpen = false;
#[On('scanQRCode')]
public function addQRProduct($qrcode)
{
$product = Product::where('qrcode', $qrcode)->first();
if ($product) {
Notification::make()
->title('Βρέθηκε το ' . __('Product.label') . ' ' . $qrcode)
->success()
->send();
$newOrderline = [
// product_id
// quantity
// tax_amount
// ....
];
// Update repeaters state...
}
}
}
2 Replies
Did you come across a solution for this? I'm doing something similar - I want to use scanning to dynamically add repeater fields.
I managed to do something with that using event & listeners.
Basically I dispatch an event $this->dispatch('scannedQrcode', $qrcode);
and then on the CreteOrder page (the create page of your resource)
I listen for that event
#[On('scannedQrcode')]
public function addScannedProduct($qrcode)
{
// your logic
}