How to only use created_at in Laravel

后端 未结 17 2071
自闭症患者
自闭症患者 2020-12-07 18:20

I want only use created_at , how to do it?

I know:

This can custom timestamps name

const CREATED_AT = \'created\';
const UPDATED_AT = \'updat         


        
17条回答
  •  借酒劲吻你
    2020-12-07 19:02

    On your model set

    const UPDATED_AT = null;

    or

    const CREATED_AT = null;

    it stops Laravel trying to update the updated_at/created_at field

    It works for Laravel 5.8

    And it is better than overwrite: setUpdatedAt in your model

    public function setUpdatedAt($value) : self 
    {
        // Do nothing.
        return $this;
    }
    

    because it is shorter and because the check for if (! is_null(static::UPDATED_AT) is happening in source code earlier than triggering setUpdatedAt

提交回复
热议问题