refear99 refear99 - 5 months ago 55
PHP Question

how to only use created_at in laravel

everyone.

I am new to laravel.

this is my questions:

this can custom timestamps name

const CREATED_AT = 'created';
const UPDATED_AT = 'updated';


this can disable timestamps

public $timestamps = false;


I want only use created_at , how to do it ?

Answer

Eloquent does not provide such functionality out of the box, but you can create it on your own using the creating event callback:

class User extends Eloquent {

    public $timestamps = false;

    public static function boot()
    {
        static::creating(function ($model) {
            $model->created_at = $model->freshTimestamp();
        });
    }

}