mercredi 27 décembre 2017

Custom created_at and use only custom created_at

I am new to Laravel.

I want to add timestamp for all insert actions in Laravel using custom field name such as ct and not using updated_at.

I came up with below, but without luck. All of my tables have ct field with not null property.

class ProductLog extends Model
{
    const CREATED_AT = 'ct';

    public $timestamps = false;

    public static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            $model->created_at = $model->freshTimestamp(); => 1)
            $model->setCreatedAt($model->freshTimestamp()); => 2)
        });
    }
}

Both of 1) and 2) still throws me an error saying 'ct' doesn't have a default value.

Any suggestion or advice would be appreciated.

Thank you in advance.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DVicUG
via IFTTT

Aucun commentaire:

Enregistrer un commentaire