| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App;
- use App\Traits\ModelTimeFormat;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelLogChanging;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class WorkOrderLog extends Model
- {
- // use ModelLogChanging;
- use ModelTimeFormat;
- protected $fillable = ['work_order_id','content','type','creator_id'];
- static public $enums = [
- 'type' => [
- '' => 0,
- '创建' => 1,
- '处理' => 2,
- '完结' => 3,
- ],
- ];
- 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 workOrder(): BelongsTo
- {
- return $this->belongsTo(WorkOrder::class);
- }
- public function creator(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- }
|