Ensure caches are cleared after a bonus score is entered
This commit is contained in:
parent
005160097b
commit
e2a41fdb9c
|
|
@ -4,11 +4,28 @@ namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
class BonusScore extends Model
|
class BonusScore extends Model
|
||||||
{
|
{
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|
||||||
|
protected static function boot()
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
static::created(function ($bonusScore) {
|
||||||
|
$bonusScore->deleteRelatedCalculatedScores();
|
||||||
|
});
|
||||||
|
|
||||||
|
static::updated(function ($bonusScore) {
|
||||||
|
$bonusScore->deleteRelatedCalculatedScores();
|
||||||
|
});
|
||||||
|
|
||||||
|
static::deleted(function ($bonusScore) {
|
||||||
|
$bonusScore->deleteRelatedCalculatedScores();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function entry(): BelongsTo
|
public function entry(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Entry::class);
|
return $this->belongsTo(Entry::class);
|
||||||
|
|
@ -23,4 +40,16 @@ class BonusScore extends Model
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Entry::class, 'originally_scored_entry');
|
return $this->belongsTo(Entry::class, 'originally_scored_entry');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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