F
Filamentβ€’8mo ago
Bruno Silva

Create related record inside infolist

How can I create a record of another model inside a infolist using an action button? I have a infolist in my "BookingResource", I want that button to create a "Invoice" (Booking and Invoice are related), how can I do that? with a modal if possible. I'm trying to do something like this but it's not working:
Actions::make([
Action::make('createInvoice')
->icon('heroicon-o-currency-dollar')
->action(function (Booking $record) {
/* Invoice::factory()->create([
// ]) // don't thing this is the right aproach */
})
->form([
TextInput::make('total')
->label('Total')
->required(),
]),
])
Actions::make([
Action::make('createInvoice')
->icon('heroicon-o-currency-dollar')
->action(function (Booking $record) {
/* Invoice::factory()->create([
// ]) // don't thing this is the right aproach */
})
->form([
TextInput::make('total')
->label('Total')
->required(),
]),
])
The motive is that I need the booking to have a invoice featured before I can complete the booking, if there's a better a way to do this, let me know
Solution:
ok, I've made an Action like this: ```php Action::make('createInvoice') ->form(InvoiceForm::getForm(true))...
Jump to solution
5 Replies
Bruno Silva
Bruno SilvaOPβ€’8mo ago
anyone?
LeandroFerreira
LeandroFerreiraβ€’8mo ago
what isn't working?
Bruno Silva
Bruno SilvaOPβ€’8mo ago
Actually, I just don't know how to create a invoice related to that booking, from the infolist, for example, I want button "create invoice" to create a invoice directly related to that booking, but I don't know how to do that I think the ->form() method in the Action don't work, because I can't chain a ->relationship method on it
No description
Solution
Bruno Silva
Bruno Silvaβ€’8mo ago
ok, I've made an Action like this:
Action::make('createInvoice')
->form(InvoiceForm::getForm(true))
->action(function (Booking $record, Action $action, array $data) {
$record->invoice()->create($data);
$record->save();
})
->icon('heroicon-o-arrow-right-start-on-rectangle'),
Action::make('createInvoice')
->form(InvoiceForm::getForm(true))
->action(function (Booking $record, Action $action, array $data) {
$record->invoice()->create($data);
$record->save();
})
->icon('heroicon-o-arrow-right-start-on-rectangle'),
in that getForm method, I've added a param to prevent relationship errors by hiding some fields. The problem was that I didn't want to make different forms for the same thing, so now I have only one form that I can make a few changes if I pass that param
Bruno Silva
Bruno SilvaOPβ€’8mo ago
thanks anyway Leandro πŸ™
Want results from more Discord servers?
Add your server