From 95b2af5485bf401986b00b26c1573873879a5024 Mon Sep 17 00:00:00 2001 From: liapples Date: Thu, 12 Aug 2021 10:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=88=9B=E5=BB=BA=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=92=8C=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E4=B8=A4?= =?UTF-8?q?=E4=B8=AA=E8=AE=BF=E9=97=AE=E5=99=A8=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?HasDateTimeFormatter=E4=BB=A3=E6=9B=BF=EF=BC=8C=E4=B8=8D?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=BD=AC=E6=8D=A2=E6=97=B6=E9=97=B4=E6=88=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/BaseModel.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) 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'); } }