© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
6 replies
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:

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
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
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Is there a way to show related record information in a textEntry inside infolist?
FilamentFFilament / ❓┊help
2y ago
CreateAction inside infoList?
FilamentFFilament / ❓┊help
13mo ago
Table inside Infolist
FilamentFFilament / ❓┊help
3y ago
tiptapeditor inside infolist
FilamentFFilament / ❓┊help
3y ago