Laravel - Sending Notification When Event Starts

I developed a little Event System. By creating a new event the event startdate can be set on the future.

In this case I´m trying to send out a notification to a user, where is participant of this event, that the event started. How i can solve this?

I tried something like this with scheduling and an own ServiceProvider:

$challenges = Auth::User()->challenges()->where('startdate', '<=', Carbon::now())->get();
        foreach($challenges as $challenge) {



But yes, so the notification will send out everytime..not a good solution. I need them only one time when the event startdate switches from future to now.

Do you have an idea? Many thanks in advance!!




Personally I would just create a new field in database that would indicate if you sent the notifications. If you did not and the start date is after now you want to send notifications and set the flag to 1/true.

Still, the solution you created is not the best/most performant, since now you'll query database at every single request. The better would be to create some CRON job to perodically check for such thing.

For more information check this out:

This will provide you some basic informations about what you need to do to perodically make some actions.You may also want to read about Artisan Commands so you can run it every x minutes.