ldc-gen-game-web/app/Models/InstantWin.php

95 lines
2.2 KiB
PHP
Raw Permalink Normal View History

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