[ '' => 0, '创建' => 1, '处理' => 2, '终审' => 3, '完结' => 4, ], 'tag' => [ '创建' => 0, '完结' => 1, '标记' => 2, ], ]; function __construct(array $attributes = []) { foreach (self::$enums as &$enum) { $enum = $enum + array_flip($enum); } parent::__construct($attributes); } public function getTypeAttribute($value) { if (!$value) return ''; return self::$enums['type'][$value]; } public function setTypeAttribute($value) { if (!$value) return; if (is_numeric($value)) { $this->attributes['type'] = $value; } else { $this->attributes['type'] = self::$enums['type'][$value]; } } public function getTagAttribute($value) { if (!$value) return ''; return self::$enums['tag'][$value]; } public function setTagAttribute($value) { if (!$value) return; if (is_numeric($value)) { $this->attributes['tag'] = $value; } else { $this->attributes['tag'] = self::$enums['tag'][$value]; } } public function creator(): BelongsTo { return $this->belongsTo(User::class); } }