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

Jeyziii's avatar

publish and hide a post on specific date and time

Help! I need to publish and hide a post by specific date and time. I tried both codes, but it doesn't work. It works fine if retrieve with just date, but I need to retrieve it with time.

$latest_article=Article::whereDate('published_at', '<=', Carbon::now())
                                ->WhereDate('expired_at', '>', Carbon::now())
                                ->Where('status', 1)
                                ->latest()
                                ->limit(3)
                                ->get();
$latest_article=Article::whereDate('published_at', '<=', Carbon::now())
                                ->WhereDate('expired_at', '>', Carbon::now())
                                ->whereTime('published_at', '<=', Carbon::now())
                                ->WhereTime('expired_at', '>', Carbon::now())
                                ->Where('status', 1)
                                ->latest()
                                ->limit(3)
                                ->get();
0 likes
1 reply

Please or to participate in this conversation.