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

dmcglone27's avatar

Publish on a later date episode

Does anyone know what episode discusses publishing something at a later date? I remember one where @JeffreyWay Demonstrated this, but forgot which one it was.

0 likes
5 replies
mstnorris's avatar

I can't remember the episode, but why do you need that?

Apologies for jumping the gun, if you want to know how to do it, just create a query scope for whatever model you're retrieving and set a where clause to check the published_at timestamp. When you're creating a resource, in this case an Article, then set a published_at timestamp to a date in the future.

Article Model

protected $dates = [
    'published_at'
];

public function scopePublished($query)
{
    $query->where('published_at', '<=', Carbon::now());
}

ArticleController Controller

public function index()
{
    $articles = Article::with('user')->published()->latest('published_at')->paginate(5);

    return view('articles.index', compact('articles'));
}

The above will get all of the published articles, in reverse chronological order (latest first, according to the published_at timestamp) and paginate the results.

Hope that helps.

Sorry for not answering your actual question about the lesson video, I have no idea ;)

jimmck's avatar

Do you mean the April 22, 2015 Scheduling Commands and Tasks episiode?

dmcglone27's avatar

Thanks guys, I found it. @mstnorris Yeah, I wanted to see how Jeff did it, because I got confused. Turns out I completely forgot to add the db field into my Model.

@jimmck, it was the "fun with dates" episode.

mstnorris's avatar

Weirdly I found that episode and skimmed through it but thought you couldn't mean that as it was from 2013!

So was it the $dates property I mentioned?

dmcglone27's avatar

@mstnorris, Yeah that was it. It's been a while since I've needed to created my own date field, so I completely forgot how to format it to use with carbon .

Please or to participate in this conversation.