From 6c22581e4ff7d9128200e6815428f938c951ef2a Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Thu, 30 Apr 2026 11:56:46 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20reset=20cache=20when=20as?= =?UTF-8?q?sociating=20new=20relation=20to=20document=20model=20#144=20-?= =?UTF-8?q?=20from=20cee3d11b?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Document.php | 5 +++-- app/Models/Documentable.php | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 app/Models/Documentable.php 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()); + } +}