You must enable Announce by adding FilamentAnnouncePlugin class to your Filament Panel's plugin() or plugins([]) method:
useRupadana\FilamentAnnounce\FilamentAnnouncePlugin;useFilament\Support\Colors\Color;classCustomersPanelProviderextendsPanelProvider{publicfunctionpanel(Panel $panel):Panel {return $panel...->plugin(FilamentAnnouncePlugin::make()->pollingInterval('30s')// optional, by default it is set to null->defaultColor(Color::Blue)// optional, by default it is set to "primary") }}
To override the plugins announcementResource with your own custom resource, you should append usingResource method when registering the plugin:
useRupadana\FilamentAnnounce\FilamentAnnouncePlugin;useFilament\Support\Colors\Color;classCustomersPanelProviderextendsPanelProvider{publicfunctionpanel(Panel $panel):Panel {return $panel...->plugin(FilamentAnnouncePlugin::make()->usingResource(MyCustomAnnouncementResource::class)->pollingInterval('30s')// optional, by default it is set to null->defaultColor(Color::Blue)// optional, by default it is set to "primary") }}
Now you can announce whatever to users:
useApp\Models\User;useRupadana\FilamentAnnounce\Announce;Announce::make()->title('Big News!')->icon('heroicon-o-megaphone')->body('Filament can now show very important message to specific users!')->disableCloseButton()// Optional, if you want ur announcement discloseable->announceTo(User::all());
Title and Body Alignment
By default, the alignments will be start and you might want to adjust them:
useApp\Models\User;useFilament\Support\Enums\Alignment;useRupadana\FilamentAnnounce\Announce;Announce::make()->title('Big News!')->icon('heroicon-o-megaphone')->body('Filament can now show very important message to specific users!')->alignment(Alignment::Center)// this will set both title and body alignments (common alignment)->titleAlignment(Alignment::Start)// this will set title alignment and take precedence over common alignment methods->bodyAlignment(Alignment::Start)// this will set body alignment and take precedence over common alignment methods->actions([Action::make('view')->button(),Action::make('undo')->color('gray'), ])->announceTo(User::all());
You can also use alignStart(), alignCenter(), alignEnd(), alignJustify(), alignBetween(), alignLeft() and alignRight() for your convenience.
Add Actions to Announce
Since Announce extends Filament Notification, you can add Filament Notification Actions to your announcements:
useApp\Models\User;useRupadana\FilamentAnnounce\Announce;Announce::make()->title('Big News!')->icon('heroicon-o-megaphone')->body('Filament can now show very important message to specific users!')->actions([Action::make('view')->button(),Action::make('undo')->color('gray'), ])->announceTo(User::all());