Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

birdietorerik's avatar

How to do this

Hi!

Have created a application laravel 10.x and vue 2

I am using notification in my application. Must check if new notifications is present every 55 seconds

Today am am using in my vue compoent

  mounted() {
        console.log("NOTIFICATIONS MAUNTED 3");
        //this.getNotifications();
        this.interval = setInterval(
            function () {
                this.getNotifications();
            }.bind(this),
            55000
        );
    },
...
...

 getNotifications() {
            var _this = this;
            axios
                .get("getnotificationFlow", {
                    params: {
                        status: 5,
                    },
                })
                .then(function (response) {
                    _this.notifications = response.data.data.notfikikations;
                    _this.numbofnotif = _this.notifications.length;
                    console.log("Notifications here ");
                })
                .catch(function (error) {
                    console.log("Error getnotificationFlow :" + error);
                })
                .then(function () {});
        },

Is there some better way to update my component -> notification NOT use setInterval ?

0 likes
2 replies
martinbean's avatar

Have created a application laravel 10.x and vue 2

@birdietorerik Why are you using old versions of libraries?

You also don’t need to poll for new notifications. Notifications are broadcastable. You can receive notifications as and when they’re created and sent (https://laravel.com/docs/notifications#listening-for-notifications):

Echo.private(`App.Models.User.${userId}`).notification((notification) => {
    console.log(notification.type);
});

Please or to participate in this conversation.