© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
3 replies
Quin.

Notification broadcasting with an observer on create

Hey! I have a question about the filament notifications, Right now i have when i edit my Opportunity that it sends a broadcast.
public function save(bool $shouldRedirect = true): void
    {
        $user = auth()->user();

        $user->notify(
            Notification::make()
                ->title('Saved successfully')
                ->toBroadcast(),
        );
    }
public function save(bool $shouldRedirect = true): void
    {
        $user = auth()->user();

        $user->notify(
            Notification::make()
                ->title('Saved successfully')
                ->toBroadcast(),
        );
    }



I really wanted that when i call my notification
class OpportunityNotification extends Notification implements ShouldQueue
{
    use Queueable;

    private Opportunity $opportunity;

    public function __construct(Opportunity $opportunity)
    {
        //
        $this->opportunity = $opportunity;
    }

    public function via($notifiable): array
    {
        return ['broadcast', 'slack'];
    }

    public function toBroadcast($notifiable): BroadcastMessage
    {
        return new BroadcastMessage([
            'opportunity' => 'Checkout this new opportunity: '.$this->opportunity->title."\n".$this->opportunity->url,
        ]);
    }

    public function toSlack($notifiable): SlackMessage
    {
        return (new SlackMessage)
            ->content('Checkout this new opportunity: '.$this->opportunity->title."\n".$this->opportunity->url);
    }

    public function toArray($notifiable): array
    {
        return [];
    }
}
class OpportunityNotification extends Notification implements ShouldQueue
{
    use Queueable;

    private Opportunity $opportunity;

    public function __construct(Opportunity $opportunity)
    {
        //
        $this->opportunity = $opportunity;
    }

    public function via($notifiable): array
    {
        return ['broadcast', 'slack'];
    }

    public function toBroadcast($notifiable): BroadcastMessage
    {
        return new BroadcastMessage([
            'opportunity' => 'Checkout this new opportunity: '.$this->opportunity->title."\n".$this->opportunity->url,
        ]);
    }

    public function toSlack($notifiable): SlackMessage
    {
        return (new SlackMessage)
            ->content('Checkout this new opportunity: '.$this->opportunity->title."\n".$this->opportunity->url);
    }

    public function toArray($notifiable): array
    {
        return [];
    }
}


That is called in my observer created
 public function created(Opportunity $opportunity): void
    {
        $opportunity->notify(new OpportunityNotification($opportunity));
    }
 public function created(Opportunity $opportunity): void
    {
        $opportunity->notify(new OpportunityNotification($opportunity));
    }


When i create this record that the notification will send in my laravel dashboard just as it does in mine save function for the edit notification? Is there anyway or better way to do this? Couldn't really find antything in the docs
Solution
 public function created(Opportunity $opportunity): void
    {
        $user = auth()->user();
        $user->notify(Notification::make()->title('Checkout this new opportunity: '. $opportunity->title."\n". $opportunity->url)->toBroadcast());
    }
 public function created(Opportunity $opportunity): void
    {
        $user = auth()->user();
        $user->notify(Notification::make()->title('Checkout this new opportunity: '. $opportunity->title."\n". $opportunity->url)->toBroadcast());
    }


i thought to difficult this is the easy way to do it 😄
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

Sending a notification with an observer
FilamentFFilament / ❓┊help
3y ago
Notification Broadcasting Help
FilamentFFilament / ❓┊help
3y ago
Database notification error Broadcasting [database-notifications.sent] on channels
FilamentFFilament / ❓┊help
2y ago
Observer created not executing save, create or insert
FilamentFFilament / ❓┊help
2y ago