'boolean', 'is_completed' => 'boolean', 'sort_order' => 'integer', 'completed_at' => 'datetime', ]; // ─── Relationships ─────────────────────────────── public function shipment(): BelongsTo { return $this->belongsTo(Shipment::class); } public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } public function completedBy(): BelongsTo { return $this->belongsTo(User::class, 'completed_by'); } // ─── Scopes ─────────────────────────────────────── public function scopeIncomplete($query) { return $query->where('is_completed', false); } public function scopeRequired($query) { return $query->where('is_required', true); } // ─── Helpers ───────────────────────────────────── /** * تکمیل یک آیتم چک‌لیست توسط کارمند. */ public function complete(?int $userId = null, ?string $note = null): void { $data = [ 'is_completed' => true, 'completed_by' => $userId ?? Auth::id(), 'completed_at' => now(), ]; if ($note) { $existing = $this->notes ? $this->notes . "\n\n" : ''; $data['notes'] = $existing . '[' . now()->format('Y-m-d H:i') . '] ' . $note; } $this->update($data); } }