Conditional confirmation before create

on a CreateAction header action for a table, I want to do a check on submit that will look for an existing record with a similar form value and if one is found, a confirmation is displayed before its created and if confirmed, it proceeds to create the record and delete another record. Suggestions on best way to go about that?
1 Reply
Ricardo Sawir
Ricardo Sawir2y ago
I can think of
CreateAction::make()
->requiresConfirmation(fn ($livewire) => Record::query()->where('slug', $livewire->data['slug'])->exists())
->action(fn ($livewire) => Record::query()->firstOrCreate(['slug' => $livewire->data['slug']])),
CreateAction::make()
->requiresConfirmation(fn ($livewire) => Record::query()->where('slug', $livewire->data['slug'])->exists())
->action(fn ($livewire) => Record::query()->firstOrCreate(['slug' => $livewire->data['slug']])),
Want results from more Discord servers?
Add your server