A
A
Andrey Tokmakov2016-04-03 15:43:12
Blogs
Andrey Tokmakov, 2016-04-03 15:43:12

How to use created_at and updated_at (post creation and update date) correctly?

Actually, everything seems to be as usual: create a post - put the current date in both fields, update the post - put the current date in the updated_at field.
And now the question is, by which field to sort the posts?
What is the difficulty? And the difficulty is this:
I am creating a post today, but it is large and it takes 2-3 days to write it, so it hangs in drafts. 2-3 days passed, and the post was never published, well, hands didn’t reach him, for that other posts were written during this time. As a result, we get - if we display the posts by the date of creation, then the first post will be released at the end, as long ago created, although it should be the last one, we will display by the update date everything will be as it should, it would seem, BUT - there was a typo in one post, in another, corrected 1 letter here and there and that's it, the posts were sorted haphazardly, it turns out wrong.
Any ideas how to be? Who gets out of this situation?
Well, for one thing - what date to display in the post? Of course, the date of the last modification will go into the meta tag, but in the post itself, the date of creation / modification?
So far, it only comes to mind to create another 1 field of type published to store the date, but this somehow doesn’t work out right

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mylistryx, 2016-04-03
@Mylistryx

I use created_at and updated_at as a logger for creating and updating a publication, but the status itself that an article has been published can be changed either through the status of the entry, or the published field, which is null by default, but if we pass a flag from the form that this article is published, then we do $model->touch('published'); The TimestampBehavior has a method to push the date to the desired property of the class.

M
Maxim Timofeev, 2016-04-03
@webinar

Here you need to ask yourself the question "why do I need these dates?". If it's just what it would be, can it be easier to sort by id?
If your posts are written by three for only the administrator, then update created_at in the admin controller or display the ability for the admin to change this date in the form of a datetime picker. Then he will also be able to do delayed publications.
Here, even if we proceed from the banal logic, created_at is the date of publication and not the date of entry into the database.
You can put down the date created_at, only if there is a tick to publish, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question