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(),
  ]),
])


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:

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
Was this page helpful?