initial commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class CatRegistration extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'cat_id', 'association_id', 'registration_number', 'pedigree_number',
|
||||
'certificate_number', 'issue_date', 'title', 'ownership_status',
|
||||
'is_primary', 'notes',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['issue_date' => 'date', 'is_primary' => 'boolean'];
|
||||
}
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleting(function (CatRegistration $registration) {
|
||||
$registration->loadMissing('documents');
|
||||
foreach ($registration->documents as $document) {
|
||||
if ($document->file_path) {
|
||||
Storage::disk('public')->delete($document->file_path);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function cat() { return $this->belongsTo(Cat::class); }
|
||||
public function association() { return $this->belongsTo(CatAssociation::class, 'association_id'); }
|
||||
public function documents() { return $this->hasMany(CatRegistrationDocument::class)->latest(); }
|
||||
}
|
||||
Reference in New Issue
Block a user