You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.1 KiB
65 lines
2.1 KiB
<?php |
|
|
|
namespace Plugins\Notebook\Model; |
|
|
|
use App\Model\Attribute\CreateSql; |
|
use App\Model\Base\Administrators; |
|
use App\Model\Model; |
|
|
|
/** |
|
* 笔记本 |
|
* @property int $id ID |
|
* @property string $title 标题 |
|
* @property string $content 内容 |
|
* @property int $administrators_id 创建人 |
|
* @property int $latest_administrators_id 最后修改人 |
|
* @property string $create_time 创建时间 |
|
* @property string $update_time 更新时间 |
|
* @property int $delete_time 删除时间 |
|
*/ |
|
#[CreateSql(<<<SQL |
|
CREATE TABLE `sd_notebook` ( |
|
`id` int NOT NULL AUTO_INCREMENT COMMENT 'ID', |
|
`title` varchar(127) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '标题', |
|
`content` text COLLATE utf8mb4_general_ci COMMENT '内容', |
|
`administrators_id` int NOT NULL COMMENT '创建人', |
|
`latest_administrators_id` int NOT NULL COMMENT '最后修改人', |
|
`create_time` datetime NOT NULL COMMENT '创建时间', |
|
`update_time` datetime NOT NULL COMMENT '更新时间', |
|
`delete_time` int DEFAULT NULL COMMENT '删除时间', |
|
PRIMARY KEY (`id`) |
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='笔记本' |
|
SQL)] |
|
class Notebook extends Model |
|
{ |
|
protected ?string $table = 'notebook'; |
|
|
|
protected array $casts = [ |
|
...self::DEFAULT_CASTS, |
|
|
|
// 更多casts |
|
]; |
|
|
|
protected array $fillable = ["title", "content", "administrators_id", "latest_administrators_id"]; |
|
|
|
public function setAdministratorsIdAttribute($value): int |
|
{ |
|
return $this->attributes['administrators_id'] = (int)$value; |
|
} |
|
|
|
public function setLatestAdministratorsIdAttribute($value): int |
|
{ |
|
return $this->attributes['latest_administrators_id'] = (int)$value; |
|
} |
|
|
|
public function createAdmin() |
|
{ |
|
return $this->belongsTo(Administrators::class, 'administrators_id'); |
|
} |
|
|
|
public function latestAdmin() |
|
{ |
|
return $this->belongsTo(Administrators::class, 'latest_administrators_id'); |
|
} |
|
} |
|
|
|
|