How to change default timestamp fields name in Laravel

Updated at 07-Jan-2022, By samar

How to change default timestamp fields name in Laravel

Through the use of the programming language, we will work together to solve the "How to change default timestamp fields name in Laravel" puzzle in this lesson.

Sometimes you have to change the default timestamp field name in Laravel. In case you have a non-Laravel database with created_time and updated_time columns then you can use this code snippet to solve the problem.
  • Change default timestamp fields

    class Post extends Model
    {
        const CREATED_AT = 'created_time';
        const UPDATED_AT = 'updated_time';
    }
    

    If your timestamp columns (created_at , updated_at) are named differently, in case you are working with a non-Laravel database and you have columns created_time and updated_time in the table. You can specify them in the model, too.

Back to code snippet queries related laravel