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

Maison012's avatar

Laravel push notification does not work as except

I am building a real time notification system for my reminders. And use laravel pusher do create event also created a cron job run everyMinute. As frontent i use vue js component. I save notification to a tasble on debugger, and after event created also save record on db. Now my problem is i fetch notificaton every time i reload pageXOffset, and event does not add record on this.messages=[].

Vue module

export default {
    template: `
        <div>
            <ul class="navbar-p prevent-close">
                <li v-for="message in messages" :key="message.id" class="dropdown-item d-block ">
                    <span>
                        <i class='bx bxs-low-vision'></i>
                    </span>
                    <p>{{ message.title }}</p>
                    <sup class="text-secondary">{{ message.description }}</sup>
                    <br />
                    <sup class="text-info">DT: {{ message.remindTime }}</sup>
                    <hr class="p-0 m-0" />
                </li>
            </ul>
        </div>
    `,

    data() {
        return {
            messages: [],
        }
    },
    
    mounted() {
        axios.get('/notifications').then(response => {
            // console.log(response.data.notifiy);
            this.messages = response.data.notifiy;
            $(".fa-bell").addClass('fa-notification-custom-badge');
        })

        // // Enable pusher logging - don't include this in production
        Pusher.logToConsole = true;

        var pusher = new Pusher('14eb3b08697886e4d41a', {
            cluster: 'eu'
        });

        var channel = pusher.subscribe('reminder-notification-chanel');
        var notification = [];
        channel.bind('reminder-notification-event', function(data) {
            // alert(JSON.stringify(data.message))
            // console.log(data.message)
            var dataOb = data.message;

            notification.push(dataOb);
            $(".fa-bell").addClass('fa-notification-custom-badge');
                
        });

        this.messages.push(notification);
    },

}

CronJob laravel

 public function handle(ReminderEventServices $reminderServices)
    {
        // return 0;
        // $getLastReminders = $reminderServices->ReminderEvent(); 
        $getLastReminders = Reminder::where('remindTime', '<', 
            Carbon::now()->addHours(3)/*->addMinutes(2)*/->toDateTimeString()
        )
        ->where('remindTime', '>=',
            Carbon::now()->toDateTimeString()
        )->get();

        if ($getLastReminders) {
            foreach($getLastReminders as $reminder) {
                if (!Notification::where('title', $reminder->title)->exists()) {
                    $notification = Notification::create([
                        'title'         => $reminder->title,
                        'description'   => $reminder->description,
                        'remindTime'    => $reminder->remindTime
                    ]);
                }

                event(new ReminderEvent($reminder));
            }
        }
    }
0 likes
0 replies

Please or to participate in this conversation.