fix: 🐛 reset cache when associating new relation to document model #144
This commit is contained in:
parent
60e6ab4294
commit
cee3d11b4c
2 changed files with 38 additions and 2 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
35
app/Models/Documentable.php
Normal file
35
app/Models/Documentable.php
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphPivot;
|
||||
|
||||
/**
|
||||
* @property integer $id Id of the document.
|
||||
* @property \App\Models\Document $document_id Name of the document.
|
||||
* @property \App\Models\DocumentCategory|\App\Models\DocumentTag $documentable_id Name of the category or tag.
|
||||
* @property class-string<static> $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());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue