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

Jeyziii's avatar

Automatic publishing and hiding post using time and date

Hi! I am developing a news website, is there a way to automatically publish and hide/archive a content you made on a schedule? Like I will set a date for it to be publish and set another date for it to be hidden/archived. is there a built in function for it in the Laravel or package?

0 likes
5 replies
lbecket's avatar

Your question is vague. Are you asking about conditionally rendering content or are you talking about publishing content on some kind of schedule? Or maybe both? Or something else? You're going to have to elaborate.

1 like
Jeyziii's avatar

@bobbybouwmann Sorry, I am talking about publishing the content on a schedule. Like making a content and choosing the date and time for it to be published and archived.

bobbybouwmann's avatar
Level 88

@Jeyziii Not sure why you tagged me, but I can try to help you out.

Usually, you would set a published_at field in the database. If this field is empty, the post is not published. If you want to publish it, you add a date to that field. If the date is in the past, the post is "published". If it's in the future you won't see it.

You will get a query like this

Post::whereDate('published_at', '<=', Carbon::now())->get();
1 like
AamirSohailKmAs's avatar

@jeyziii laravel has a jobs feature, You can create a job for publishing content on a specific date and time.

1 like

Please or to participate in this conversation.