Clear cache values when a flag is set on an entry
This commit is contained in:
parent
a52b91d601
commit
3d8fa816c6
|
|
@ -5,6 +5,7 @@ namespace App\Models;
|
|||
use App\Enums\EntryFlags;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class EntryFlag extends Model
|
||||
{
|
||||
|
|
@ -14,8 +15,36 @@ class EntryFlag extends Model
|
|||
'flag_name' => EntryFlags::class,
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::created(function ($flag) {
|
||||
$flag->deleteRelatedCalculatedScores();
|
||||
});
|
||||
|
||||
static::updated(function ($flag) {
|
||||
$flag->deleteRelatedCalculatedScores();
|
||||
});
|
||||
|
||||
static::deleted(function ($flag) {
|
||||
$flag->deleteRelatedCalculatedScores();
|
||||
});
|
||||
}
|
||||
|
||||
public function entry(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Entry::class);
|
||||
}
|
||||
|
||||
public function deleteRelatedCalculatedScores(): void
|
||||
{
|
||||
$entry = $this->entry;
|
||||
if ($entry) {
|
||||
$entry->calculatedScores()->delete();
|
||||
Cache::forget('entryScore-'.$entry->id.'-seating');
|
||||
Cache::forget('entryScore-'.$entry->id.'-advancement');
|
||||
Cache::forget('audition'.$entry->audition_id.'seating');
|
||||
Cache::forget('audition'.$entry->audition_id.'advancement');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue