Β© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filamentβ€’3y agoβ€’
1 reply
Quin.

Sending a notification with an observer

Ello!
I was reading the documentation but i couldn't find the right answer on my question. I wanted to send a notification when Opportunity created? Is there anyway to do this in the observer that it sends the notification on your laravel dashboard?

OpportunityNotification:

  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 [];
    }
  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 [];
    }


OpportunityObserver:
   public function created(Opportunity $opportunity): void
    {
        $opportunity->notify(new OpportunityNotification($opportunity));
    }
   public function created(Opportunity $opportunity): void
    {
        $opportunity->notify(new OpportunityNotification($opportunity));
    }


i am broadcasting the notification πŸ˜„
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel β€’ Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Notification broadcasting with an observer on create
FilamentFFilament / β“β”Šhelp
3y ago
Sending a SMS Notification, just like a Mail Notification
FilamentFFilament / β“β”Šhelp
12mo ago
Sending notification after action
FilamentFFilament / β“β”Šhelp
2y ago
Notification send before observer creating function is executed
FilamentFFilament / β“β”Šhelp
14mo ago