标签:min class 定义 UNC 监听 eloquent mysql updating 框架
按官方文档把格式属性定义为‘U‘,无法让框架自动写入时间戳,看来只能通过其他方法了。
定义一个模型基类,然后监听事件即可解决:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model as EloquentModel; class Model extends EloquentModel { public $timestamps = false; public static function boot() { parent::boot(); static::creating(function ($model) { $model->created_at = now()->timestamp; }); static::updating(function ($model) { $model->updated_at = now()->timestamp; }); } }
标签:min class 定义 UNC 监听 eloquent mysql updating 框架
原文地址:https://www.cnblogs.com/tudou1223/p/10117234.html