#Notification broadcast for observer when created

24 messages · Page 1 of 1 (latest)

unique harness
#

I am just beginning with the broadcast features, i really don't know what is going wrong. Anyone has a idea?

gleaming dagger
#

i really don't know what is going wrong
I'm afraid we don't know either, because we have no clue what's the issue is you're facing
Also, kind reminder to review the #rules and use relevant code snippets instead of screenshots

unique harness
#

sorry in the future i will use code snippets! I will look futher in to it

gritty coyote
#

what’s the error you are getting?

unique harness
#

i am getting no error that's just it :/

#

i have also tried this with a notification instead of a event

#
  public function created(Opportunity $opportunity): void
    {
//        $opportunity->notify(new OpportunityNotification());
        $opportunity->title = 'test';
        event(new OpportunityCreateEvent($opportunity->title));
    }
#
class OpportunityNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct()
    {
    }

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

    public function toBroadcast($notifiable): BroadcastMessage
    {
        return new BroadcastMessage([
            'data' => 'Your notification data',
        ]);
    }

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

but that't didn't work either

gleaming dagger
#

Sounds like your client-side isn't set up properly, check your browser's devtools for errors. You might also want to check out Pusher, as that works pretty much out of the box, allowing you to focus purely on functionality first, if that's working you can swap it for other implementations
Also, once again, please use code-snippets

unique harness
#

It works because it tested it on my filament side of the project and the notification just shows up so that isn't problem 😦

gleaming dagger
#

So.. what exactly is the issue if it works..?

unique harness
#

Well the event or notification should fire of it is created but it never popsup in the site

gleaming dagger
unique harness
#
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
    forceTLS: true
});
#

i have that 😄

gleaming dagger
#

You'd also have to listen to the messages

unique harness
#

like in the javascript you mean?

#

or in the EventServiceProvider?

gleaming dagger
#

On the client-side

unique harness
#
{
    /**
     * The event to listener mappings for the application.
     *
     * @var array<class-string, array<int, class-string>>
     */
    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
        Opportunity::class => [
            OpportunityObserver::class,
        ],
        NotificationSending::class => [
            OpportunityCreateEvent::class,
        ],
    ];
}```

So i don't have to do this in here?
gleaming dagger
#

Those are different things.. One doesn't exclude the other

#

I'd suggest to read through the docs