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

davorminchorov's avatar

Publishing Posts In The Future On A Specific Date And TIme.

Hey,

Let's say that I have a blog and I want to schedule posts to be published in the future on a selected date and time. Jeffrey uses this on Laracasts to post new lessons when he's on vacation.

But the thing I am not sure is how would I accomplish this and where would I put the publishing logic? Should I use events? Cron jobs? Queues? How would I check constantly if the current date and time is equal to the scheduled date and time?

0 likes
7 replies
taijuten's avatar

I'd do the following:

  • add another column to your post model, published_at (timestamp)
  • Create a scope (or global scope) for your post model, showing published posts only.
  • Order your posts by published_at
2 likes
davorminchorov's avatar

What if I want to do something else on the scheduled date? Maybe send an email to all followers that the new article was published?

taijuten's avatar
Level 10

I'd run a scheduled task / cron job for sending notifications, but not tie this directly to the publishing.

You can have it run every 10 minutes or so, to send out new updates, or whatever you require (most places do it nightly, and send out an email with all new ones)

1 like
Moe's avatar

Write a console command that gets the posts that should be published "today" and let it mail to they who will receive information like that. Next you schedule this command once a day.

1 like
davorminchorov's avatar

Ok It seems like going with the scheduled tasks is the way to go. Thanks :)

Do I have to be on linux or can that be tested on Windows as well?

taijuten's avatar

Give it a go Ruffles, also something I'd like to know.

I'd like to think that events will work on whatever environment.

Please or to participate in this conversation.