© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago•
4 replies
biebthesecond

Saving resource when executing Action

Good evening,

Is it possible for me to programmatically save edited resource fields before the code of an action gets executed? I can't find much in the documentation (Or I'm tired 😴 )

Reason why this is important
I had a customer e-mail me today that generating an
order
order
from a
quotation
quotation
(both resources) was broken. After some testing, I'm highly under the suspicion that they simply forgot to save the Quotation resource before clicking the action to turn it into an Order. A silly mistake, but this also implies its apparently not user-friendly enough, so I'd like to fix it if possible, preferably programmatically.

Making every field autosave through
->afterStateUpdated()
->afterStateUpdated()
is not an option because its simply too many fields (30 something), and it's also kinda ugly.

Would there be a method or (livewire) event I could use to save the resource fields before (or during)
->action()
->action()
gets called? Or would there be hack to get around this?

Thanks in advance!

Code of the defined actions for some clarity
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Actions::make([
                    CreatePdfAction::action(),
                    CreateRevisionAction::action(),
                    CompleteQuotationAction::action(),
                ])->columnSpanFull(),
                // More form stuff,
              ]);
    }
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Actions::make([
                    CreatePdfAction::action(),
                    CreateRevisionAction::action(),
                    CompleteQuotationAction::action(),
                ])->columnSpanFull(),
                // More form stuff,
              ]);
    }


code of the action which needs the resource to be saved
->action(function (?Quotation $record, array $data) {
   if (!self::allowedToComplete($record)) {
      self::notifyError();
      return;
   }
   app(CompleteQuotationPipeline::class)($record, $data);
      return redirect(route('filament.admin.resources.quotations.edit', $record));
   });
->action(function (?Quotation $record, array $data) {
   if (!self::allowedToComplete($record)) {
      self::notifyError();
      return;
   }
   app(CompleteQuotationPipeline::class)($record, $data);
      return redirect(route('filament.admin.resources.quotations.edit', $record));
   });
Solution
Maybe something like this could work?

->before(fn ($livewire) => $livewire->save())
->before(fn ($livewire) => $livewire->save())
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

Create action when viewing resource record
FilamentFFilament / ❓┊help
3y ago
Saving related items when editing/creating a resource
FilamentFFilament / ❓┊help
3y ago
Saving forms data to resource
FilamentFFilament / ❓┊help
3y ago
Saving relationships on livewire Action
FilamentFFilament / ❓┊help
2y ago