scan_time)) { $model->scan_time = time(); } }); } protected $fillable = [ 'id', 'order_no', 'quantity', 'user_code', 'operator', 'operator_id', 'process_id', 'step_id', 'status_id', 'scan_result', 'scan_time', 'remark', 'created_by', 'updated_by', 'created_at', 'updated_at', 'deleted_at', ]; protected $casts = [ 'quantity' => 'integer', 'scan_result' => 'integer', 'scan_time' => 'integer', 'created_at' => 'integer', 'updated_at' => 'integer', 'deleted_at' => 'integer', ]; public function process(): BelongsTo { return $this->belongsTo(Process::class, 'process_id', 'id')->withTrashed(); } public function step(): BelongsTo { return $this->belongsTo(ProcessStep::class, 'step_id', 'id')->withTrashed(); } public function status(): BelongsTo { return $this->belongsTo(StepStatus::class, 'status_id', 'id')->withTrashed(); } public function getProcessNameAttribute(): string { return (string) ($this->process?->process_name ?? ''); } public function getStepNameAttribute(): string { return (string) ($this->step?->step_name ?? ''); } public function getStatusNameAttribute(): string { return (string) ($this->status?->status_name ?? ''); } public function getScanDateAttribute(): ?string { return $this->scan_time ? date('Y-m-d H:i:s', (int) $this->scan_time) : null; } }