ldc-gen-game-web/app/Models/InstantWin.php
2026-10-20 12:27:49 +02:00

94 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Traits\Models\HasActivityLog;
use App\Traits\Models\IsCachedAsCollection;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* InstantWin.
*
* @property Carbon $available_at When the instant win will be available.
* @property-read Prize $prize Associated prize.
* @property-read Participation $participation Associated participation.
* @property-read \App\Models\ActivityLog $activityLogs Activities logs One-to-many relationship.
*/
class InstantWin extends Model
{
use HasActivityLog;
use IsCachedAsCollection;
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
#[\Override]
public $timestamps = false;
/**
* The relations to eager load on every query.
*
* @var list<string>
*/
#[\Override]
protected $with = ['prize'];
// * EVENTS
/**
* Perform any actions required after the model boots.
*/
protected static function booted(): void
{
static::creating(function (): void {
InstantWin::removeCached();
Prize::removeCached();
});
static::updating(function (): void {
InstantWin::removeCached();
Prize::removeCached();
});
static::deleting(function (): void {
InstantWin::removeCached();
Prize::removeCached();
});
}
// * RELATIONSHIPS
/**
* BelongsTo Prize relation.
*
* @return BelongsTo<Prize, $this>
*/
public function prize(): BelongsTo
{
return $this->belongsTo(Prize::class, 'prize_id');
}
/**
* One to one relation participation.
*
* @return BelongsTo<Participation, $this>
*/
public function participation(): BelongsTo
{
return $this->belongsTo(Participation::class);
}
/**
* Activities logs One-to-many relationship.
*
* @return HasMany<ActivityLog, $this>
*/
public function activityLogs(): HasMany
{
return $this->hasMany(ActivityLog::class);
}
}