|
|
|
@ -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'); |
|
|
|
} |
|
|
|
} |