38 lines
960 B
PHP
38 lines
960 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace plugin\article\app\model;
|
|
|
|
use app\model\system\Admin;
|
|
use core\base\BaseModel as CoreBaseModel;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
abstract class BaseModel extends CoreBaseModel
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $appends = ['created_date', 'updated_date', 'created_name', 'updated_name'];
|
|
|
|
public function createds(): HasOne
|
|
{
|
|
return $this->hasOne(Admin::class, 'id', 'created_by')->select('id', 'real_name as created_name');
|
|
}
|
|
|
|
public function updateds(): HasOne
|
|
{
|
|
return $this->hasOne(Admin::class, 'id', 'updated_by')->select('id', 'real_name as updated_name');
|
|
}
|
|
|
|
public function getCreatedNameAttribute(): string
|
|
{
|
|
return $this->createds?->created_name ?? '';
|
|
}
|
|
|
|
public function getUpdatedNameAttribute(): string
|
|
{
|
|
return $this->updateds?->updated_name ?? '';
|
|
}
|
|
}
|