51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
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
|
|
{
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'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');
|
|
}
|
|
}
|
|
}
|