refear99 refear99 - 1 year ago 226
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 ?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download