'date', 'is_pedigree' => 'boolean', 'registry' => 'array', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; } /** * MODEL EVENTS * Membersihkan file storage secara otomatis saat record dihapus. */ protected static function booted() { static::deleting(function ($kitten) { // Hapus semua foto pedigree (slot 1-4) jika ada for ($i = 1; $i <= 4; $i++) { $field = "foto_ped_$i"; if ($kitten->$field) { Storage::disk('public')->delete($kitten->$field); } } }); } /* -------------------------------------------------------------------------- */ /* RELATIONS */ /* -------------------------------------------------------------------------- */ /** * Menghubungkan ke Master Profil Kucing (Patient Table) */ public function cat(): BelongsTo { return $this->belongsTo(Cat::class, 'cat_id'); } /** * Menghubungkan ke Event Perkawinan (Breeding Event) */ public function matting(): BelongsTo { return $this->belongsTo(Matting::class, 'matting_id'); } /* -------------------------------------------------------------------------- */ /* ACCESSORS (UI Helper) */ /* -------------------------------------------------------------------------- */ /** * Menghitung berapa banyak dokumen pedigree yang sudah diupload (0-4) */ protected function pedigreeDocsCount(): Attribute { return Attribute::make( get: function () { $count = 0; for ($i = 1; $i <= 4; $i++) { if ($this->{"foto_ped_$i"}) $count++; } return $count; } ); } /** * Badge Status Pedigree untuk Tampilan Tabel */ protected function pedigreeStatusBadge(): Attribute { return Attribute::make( get: function () { if ($this->is_pedigree) { return 'Sertifikat tersedia'; } return 'Non-pedigree'; } ); } /** * Mengambil URL Foto Pedigree Slot 1 (Thumbnail) */ protected function firstPedigreeUrl(): Attribute { return Attribute::make( get: fn () => $this->foto_ped_1 ? asset('storage/' . $this->foto_ped_1) : asset('images/default-doc.png') ); } }