© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
23 replies
Toni

Experiencing odd behaviour with custom Actions

Hi,
I have a small application where the user can design email templates and publish them. Once published, the email templates can be used in other parts of the application.
Therefore I wrote to actions: publish and unpublish Email.
This is the code for the publish action:
class PublishMailAction extends Action
{
    public static function getDefaultName(): ?string
    {
        return 'publishEmail';
    }

    protected function setUp(): void
    {
        parent::setUp();
        $this->icon('fal-check-to-slot');
        $this->label(__('mail.labels.publish'));
        $this->action(static function ($record) {
            if (MailServiceProvider::publishMailTemplate($record)) {
                MailNotifications::mailTemplatePublishedSuccess()->send();
                return true;
            }
            MailNotifications::mailTemplatePublishedFailed()->send();
            return false;
        });
    }
}
class PublishMailAction extends Action
{
    public static function getDefaultName(): ?string
    {
        return 'publishEmail';
    }

    protected function setUp(): void
    {
        parent::setUp();
        $this->icon('fal-check-to-slot');
        $this->label(__('mail.labels.publish'));
        $this->action(static function ($record) {
            if (MailServiceProvider::publishMailTemplate($record)) {
                MailNotifications::mailTemplatePublishedSuccess()->send();
                return true;
            }
            MailNotifications::mailTemplatePublishedFailed()->send();
            return false;
        });
    }
}

The unpublish action is similar, except
MailServiceProvider::publishMailTemplate
MailServiceProvider::publishMailTemplate
.

The table function from the resource:
->actions([
  ActionGroup::make([
    ActionGroup::make([
      Tables\Actions\ViewAction::make(),
      Tables\Actions\EditAction::make(),
    ])->dropdown(false),
    ActionGroup::make([
      SendTestMailAction::make(),
      PublishMailAction::make()
        ->visible(fn ($record) => !$record->is_published),
      UnpublishMailAction::make()
        ->visible(fn ($record) => $record->is_published),
    ])->dropdown(false),
  ]),
])
->actions([
  ActionGroup::make([
    ActionGroup::make([
      Tables\Actions\ViewAction::make(),
      Tables\Actions\EditAction::make(),
    ])->dropdown(false),
    ActionGroup::make([
      SendTestMailAction::make(),
      PublishMailAction::make()
        ->visible(fn ($record) => !$record->is_published),
      UnpublishMailAction::make()
        ->visible(fn ($record) => $record->is_published),
    ])->dropdown(false),
  ]),
])

The Problem is, that it seems that as soon as I publish an email template, the state is preserved.
I published the last email template, and when I click on another entry, the unpublish action is visible and all custom actions refer still to the first published item.

What am I doing wrong?

Thank you!

Edit: I have forgotten the second screenshot:
image.png
Solution
Second screenshot:
image.png
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

TableSelect V4 odd behaviour
FilamentFFilament / ❓┊help
7mo ago
Odd "jumping" behaviour when using a toggle
FilamentFFilament / ❓┊help
2y ago
Custom TextInput with suffix actions
FilamentFFilament / ❓┊help
2y ago
Custom modal actions with multiple custom buttons
FilamentFFilament / ❓┊help
2y ago