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

autefrum's avatar

How do I only send notifications during 9am to 5pm, and batch them?

The functionality I am trying to code is similar to a task management system that sends a daily update saying 'the following tasks were updated today'. In one we use (Unfuddle) each user can set a preference of 'send me task updated notifications instantly when they happen' or 'send me a daily summary of all task notifications'.

My Laravel app notifies users when "X" happens, and X can happen any time of the day or night. When X happens, it calls

$user->notify(new \App\Notifications\XHappened($x,$user));

I look up the user's preference for email or SMS notification, and toMail() or toNexmo() them.

Because I am such a nice guy, I don't want to send them a text at 3am - I want to look up $user->send_sms_after_gmt and $user->send_sms_before_gmt and only send within that Window (it's actually more complicated than that but I hope you see what I mean).

Initially I was planning to have a queue per user, but I don't think that is right. To create a queue needs human intervention - either run artisan, or edit the php files to create the queue. New users can be added ad-hoc by a subset of registered users, and queue's can't.

Also, if 7 X's happened between 3am and 5am, at 9am how do I send all of those notifications in one message?

I have looked at making each 'XHappened' a Job, and dispatching all outstanding jobs at 9am, but I am getting confused between Connections, Queues, Notifications, Jobs etc).

I don't think I am the first person to do this, and I would really appreciate if someone could suggest what classes I should be using.

Cheers

0 likes
1 reply

Please or to participate in this conversation.