kkhicher1's avatar

Select a post for one Day (Like Post of the day)

i Want to add Post of the day or word of the day feature to my Laravel project. Every day its change for 24 hours from my all posts including old post.

0 likes
4 replies
Sinnbeck's avatar

And how it the "Post of the day" determined? Do you select one at the start of the day or is it the first post made that day?

Pegasus85's avatar

You can accomplish this by using the today() helper in eloquent.


Post::where('created_at', '>', today())->get();

kkhicher1's avatar

select one at the start of the day (any random post for one day)

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Simple solution

  1. Add a new table called post_of_the_day with a column for post_id and a column for date
  2. Add a scheduled task that gets a random post and adds it to the table, with todays date
  3. Get the post by using the id and date from the post_of_the_day table

You can even get a list of all previous post ids from the table, to ensure that the same one does not come again

Please or to participate in this conversation.