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.
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?
You can accomplish this by using the today() helper in eloquent.
Post::where('created_at', '>', today())->get();
select one at the start of the day (any random post for one day)
Simple solution
Add a new table called post_of_the_day with a column for post_id and a column for date
Add a scheduled task that gets a random post and adds it to the table, with todays date
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 sign in or create an account to participate in this conversation.