refear99 refear99 - 3 months ago 38x
PHP Question

how to only use created_at in laravel


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 ?


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();