Summer Sale! All accounts are 50% off this week.

kendrick's avatar

Event Listener with Popup Notification?

Hello, I am currently thinking about a simple logic in terms of visually outputting a push notification or just a partial on the user side of the application, if a button is clicked on the second side of the application.

How should I approach my work towards implementing such a simple logic?

Current thoughts:

Controller: 

1) A method which includes the Event, which will be triggered
2) A listener to trigger the container notification (simple partial) at a chosen view

Where could I get a better insight on this logic? Maybe some documentation or articles?

How could I implement the listener logic within my view? Something like: if $session listened to this Event, show this container, with a button to X out or recognize the container for the user (like a cookie information, so if clicked the popup will be put into display: none?)?

How should I approach this logic?

0 likes
4 replies
Braunson's avatar

I think you would be better off either using native web push notifications OR using something like Pusher or the alternatives Laravel Websockets for this and then you can push real-time to specific channels.

Again if your just doing all this for one popup and only ever one, the top two may be overkill.

If you want to do it using your example, the easiest method is setting a a notification table, where you set the message to the user, and on page load, you have a partial that checks for any new notifications (provided in a global view composer) and if there are show them the user and mark them as read, so the next page load they don't appear again.

In the backend you'd trigger an event (i.e. PostApproved) and a listener would be like .. NotifySubmitterOfApproval and in that listener you would create a new notifications table entry for that user.

Personally if I'm going to be using more than just one notification, I'd make use of webpush/sockets ;-)

1 like
kendrick's avatar

@BRAUNSON - Thank you for your great feedback. Sorry for the late reply.

Could you recommend any simple tutorials or articles about the notification logic, with web push/sockets? So I could have a read or more insights?

Please or to participate in this conversation.