diff --git a/app/Models/Document.php b/app/Models/Document.php index 9d885364..99483190 100644 --- a/app/Models/Document.php +++ b/app/Models/Document.php @@ -7,6 +7,7 @@ use App\Enums\Document\DocumentStatusEnum; use App\Enums\YearsEnum; use App\Helpers\DocumentHelper; use App\Helpers\TranslationHelper; +use App\Models\Documentable; use App\Traits\Models\HasCache; use App\Traits\Models\HasTranslations; use App\Traits\Models\HasUwilImages; @@ -387,7 +388,7 @@ class Document extends Model implements TranslatableModel 'documentables', 'document_id', 'documentable_id' - )->withTimestamps(); + )->using(Documentable::class)->withTimestamps(); } /** @@ -403,6 +404,6 @@ class Document extends Model implements TranslatableModel 'documentables', 'document_id', 'documentable_id' - )->withTimestamps(); + )->using(Documentable::class)->withTimestamps(); } } diff --git a/app/Models/Documentable.php b/app/Models/Documentable.php new file mode 100644 index 00000000..a144c192 --- /dev/null +++ b/app/Models/Documentable.php @@ -0,0 +1,35 @@ + $documentable_type Class of the category or tag. + * @property-read \Carbon\Carbon $created_at Created date of the document. + * @property-read \Carbon\Carbon $updated_at Updated date of the document. + */ +class Documentable extends MorphPivot +{ + /** + * The table associated with the model. + * + * @var string|null + */ + protected $table = 'documentables'; + + /** + * Perform any actions required after the model boots. + * + * @return void + */ + protected static function booted(): void + { + static::created(fn() => Document::resetCache()); + static::updated(fn() => Document::resetCache()); + static::deleted(fn() => Document::resetCache()); + } +}