How to only use created_at in Laravel

后端 未结 17 2074
自闭症患者
自闭症患者 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:16

    I have a better answer from here for Laravel 5.2 or above.

    U can use this in model-

    class User extends Model
    {
        public $timestamps = false; // disable all behavior
        public $timestamps = true; // enable all behavior
        public $timestamps = [ "created_at" ]; // enable only to created_at
        public $timestamps = [ "updated_at" ]; // enable only to updated_at
        public $timestamps = [ "created_at", "updated_at" ]; // same as true, enable all behavior
    }
    

    So, for your question, the answer is -

    public $timestamps = [ "created_at" ]; // enable only to created_at
    

    Re-

    public $timestamps = [ "created_at" ]; 
    

    Not working in Laravel 6+

提交回复
热议问题