61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\BaseModelTrait;
|
|
use DateTimeInterface;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* App\Models\BaseAuthModel
|
|
*
|
|
* @property-read string $created_at_format 创建时间的格式化
|
|
* @property-read string $updated_at_format 更新时间的格式化
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BaseAuthModel newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BaseAuthModel newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\BaseAuthModel query()
|
|
* @mixin \Eloquent
|
|
*/
|
|
class BaseAuthModel extends Authenticatable
|
|
{
|
|
protected $dateFormat = 'U';
|
|
|
|
use BaseModelTrait;
|
|
use HasFactory;
|
|
|
|
public $connection = 'mysql'; // 使用数据库链接
|
|
protected $guarded = [];
|
|
|
|
/**
|
|
* created_at_format
|
|
*
|
|
* @comment 创建时间的格式化
|
|
* @return string
|
|
*/
|
|
public function getCreatedAtFormatAttribute(): string
|
|
{
|
|
return $this[self::CREATED_AT]->toDateTimeString();
|
|
}
|
|
|
|
/**
|
|
* updated_at_format
|
|
*
|
|
* @comment 更新时间的格式化
|
|
* @return string
|
|
*/
|
|
public function getUpdatedAtFormatAttribute(): string
|
|
{
|
|
return $this[self::UPDATED_AT]->toDateTimeString();
|
|
}
|
|
|
|
/**
|
|
* 为数组 / JSON 序列化准备日期。
|
|
*/
|
|
protected function serializeDate(DateTimeInterface $date): string
|
|
{
|
|
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
|
|
}
|
|
}
|