How to only use created_at in Laravel

后端 未结 17 2059
自闭症患者
自闭症患者 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 18:59

    My solution for this is using a new __construct method.

    See:

    class MyModel extends Eloquent {
    
        public $timestamps = false;
    
        public function __construct(array $attributes = [])
        {
                parent::__construct($attributes);
    
                $this->attributes['created_at'] = $this->freshTimestamp();
        }
    }
    

提交回复
热议问题