#Notification broadcast for observer when created
24 messages · Page 1 of 1 (latest)
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
sorry in the future i will use code snippets! I will look futher in to it
what’s the error you are getting?
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
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
It works because it tested it on my filament side of the project and the notification just shows up so that isn't problem 😦
So.. what exactly is the issue if it works..?
Well the event or notification should fire of it is created but it never popsup in the site
You'd also need to set up the client-side tho; https://laravel.com/docs/10.x/broadcasting#client-side-installation
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 😄
You'd also have to listen to the messages
On the client-side
{
/**
* 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?