Automatically delete blog post when it pass its expiry date
In my Laravel app I upload blog posts. All posts have a unix expiry date eg 1492425121
What I want to do is to automatically delete all posts that pass its expiry date.
Right now I am running a cron job each night that checks for old posts then deletes them, but is there any other way I can delete them right away?
If the issue of importance is just that the blog post shouldn't display when it has expired - then you can put a global query scope in your post model which filters all results which haven't expired.
You could also check to see if any posts have expired whenever a call is made to posts, and delete any posts that have expired before showing anything. It would also eliminate the cron job. It could be as simple as delete from posts where expire_date >= current_timestamp
@CRONIX - I believe this is the best solution for this question, am going to use this option.
How did i not think about this!?
Thanks a lot! Be blessed!