70 lines
1.6 KiB
PHP
70 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\Models\IsCachedAsCollection;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* InstantWin.
|
|
*
|
|
* @property \Illuminate\Support\Carbon $available_at When the instant win will be available.
|
|
*
|
|
* @property-read \App\Models\Prize $prize Associated prize.
|
|
* @property-read \App\Models\Participation $participation Associated participation.
|
|
*/
|
|
class InstantWin extends Model
|
|
{
|
|
use IsCachedAsCollection;
|
|
|
|
/**
|
|
* Indicates if the model should be timestamped.
|
|
*
|
|
* @var boolean
|
|
*/
|
|
public $timestamps = false;
|
|
|
|
/**
|
|
* The relations to eager load on every query.
|
|
*
|
|
* @var array<string>
|
|
*/
|
|
protected $with = ['prize'];
|
|
|
|
// * EVENTS
|
|
|
|
/**
|
|
* Perform any actions required after the model boots.
|
|
*
|
|
* @return void
|
|
*/
|
|
protected static function booted()
|
|
{
|
|
static::creating(fn () => self::removeCached());
|
|
static::updating(fn () => self::removeCached());
|
|
static::deleting(fn () => self::removeCached());
|
|
}
|
|
|
|
// * RELATIONSHIPS
|
|
|
|
/**
|
|
* BelongsTo Prize relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function prize(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Prize::class, 'prize_id');
|
|
}
|
|
|
|
/**
|
|
* One to one relation participation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function participation(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Participation::class);
|
|
}
|
|
}
|