[ '' => 0, '宝时' => 1, '承运商' => 2, ], 'is_indemnity' => [ '' => 0, '是' => 1, '否' => 2, ], 'indemnitor'=> [ '' => 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 getIsIndemnityAttribute($value) { if (!$value) return ''; return self::$enums['is_indemnity'][$value]; } public function setIsIndemnityAttribute($value) { if (!$value) return ; if (is_numeric($value)) { $this->attributes['is_indemnity'] = $value; } else { $this->attributes['is_indemnity'] = self::$enums['is_indemnity'][$value]; } } public function getIndemnitorAttribute($value) { if (!$value) return ''; return self::$enums['indemnitor'][$value]; } public function setIndemnitorAttribute($value) { if (!$value) return ; if (is_numeric($value)) { $this->attributes['indemnitor'] = $value; } else { $this->attributes['indemnitor'] = self::$enums['indemnitor'][$value]; } } public function workOrder(): BelongsTo { return $this->belongsTo(WorkOrder::class); } public function creator(): BelongsTo { return $this->belongsTo(User::class); } public function isLogisticLog(): bool { return $this->type == "承运商"; } public function isBaoShiLog(): bool { return $this->type == "宝时"; } }