diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 4a5a153..e55ea3f 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -1,28 +1,27 @@ host = env('APP_URL'); - } - - # 不转换时间戳,若使用getUpdatedAtColumn,则不能自动写入时间戳 - public function getUpdatedAtAttribute($value) + protected static function booted() { - return strtotime($value); + static::addGlobalScope('orderById', function (Builder $builder) { + $builder->orderBy((new static())->getTable().'.id', 'desc'); + }); } - # 不转换时间戳,若使用getUpdatedAtColumn,则不能自动写入时间戳 - public function getCreatedAtAttribute($value) + public function __construct(array $attributes = []) { - return strtotime($value); + parent::__construct($attributes); + $this->host = env('APP_URL'); } }