Browse Source

去掉创建时间和更新时间两个访问器,使用HasDateTimeFormatter代替,不自动转换时间戳

dev
李可松 4 years ago
parent
commit
95b2af5485
  1. 23
      app/Models/BaseModel.php

23
app/Models/BaseModel.php

@ -1,28 +1,27 @@
<?php
namespace App\Models;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class BaseModel extends Model
{
use HasDateTimeFormatter;
protected $dateFormat = 'U';
protected $host = '';
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->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');
}
}
Loading…
Cancel
Save