Create multiple records when click createAction

I have a CampaignCouponsRelationManager to add a coupon under the campaign. i want that when the user clicks on "Create coupon", 100 coupons will be automatically created without opening the form in the modal. What is the recommended way to do this?
Solution:
Assuming you are wanting to bulk create 100 coupons directly, you can use an normal header action: https://filamentphp.com/docs/3.x/tables/actions#header-actions ```php...
Jump to solution
7 Replies
toeknee
toeknee10mo ago
Add a standard Laravel observer for me, when you create a Compaign it auto-inserts 100 coupons.
ramclospapp
ramclospappOP10mo ago
thanks! but How do I prevent the modal from jumping when Tables\Actions\CreateAction::make()?
toeknee
toeknee10mo ago
Don't use a create action is you are just running an action and call the model directly. My understanding was you are creating a record then want coupons created. If you want an action to create coupons then just use a normal action and run a loop for creationg in: ->action()
ramclospapp
ramclospappOP10mo ago
I'm new to filament so I don't know all the options yet. how i can catch the click event?
toeknee
toeknee10mo ago
You don't need too Can you screenshot where you want this button to be that generated the coupons
Solution
toeknee
toeknee10mo ago
Assuming you are wanting to bulk create 100 coupons directly, you can use an normal header action: https://filamentphp.com/docs/3.x/tables/actions#header-actions
Action::make('insert_coupons')
->form([TextInput::make('qty')->numeric()])
->action(function($data, $livewire) {
$parent_id = $livewire->parent_recorrd_id;
$qty = (int) $data['qty'];
// Build a loop and create all the records as normal

// Send notification of records created
})

Action::make('insert_coupons')
->form([TextInput::make('qty')->numeric()])
->action(function($data, $livewire) {
$parent_id = $livewire->parent_recorrd_id;
$qty = (int) $data['qty'];
// Build a loop and create all the records as normal

// Send notification of records created
})

ramclospapp
ramclospappOP10mo ago
I will try and update. Thank you!
Want results from more Discord servers?
Add your server