Change created_at and updated_at names to other fields

Let’s imagine a scenario where you have an old database and re-writing codebase to Laravel. Database structure may not follow Laravel standards – created_at and updated_at fields are named differently. How can you “tell it to Laravel”?

For example, if your fields are called create_time and update_time, here’s what you do in migration:

And then, apparently, it’s pretty simple – you can override the names of these fields in your model.

And here you don’t need any more mutators or attributes – these two fields will work exactly with the same auto-fill and auto-update logic as Laravel’s native ones.

Want to generate Laravel adminpanel online?
You don’t need any packages to do that!

Source link
★ READ ALSO ★  Laravel 5.5.14 Released - Laravel News

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.