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

94 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2020-10-21 15:26:21 +02:00
<?php
namespace App\Models;
2024-02-15 15:53:36 +01:00
use App\Traits\Models\ActivityLog;
2023-12-12 12:25:45 +01:00
use App\Traits\Models\IsCachedAsCollection;
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;
2020-10-21 15:26:21 +02:00
/**
* InstantWin.
*
2024-01-31 09:03:18 +00:00
* @property \Carbon\Carbon $available_at When the instant win will be available.
*
2023-11-21 12:28:09 +01:00
* @property-read \App\Models\Prize $prize Associated prize.
* @property-read \App\Models\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
{
2024-02-15 15:53:36 +01:00
use ActivityLog;
2023-12-12 12:25:45 +01:00
use IsCachedAsCollection;
/**
* Indicates if the model should be timestamped.
*
* @var boolean
*/
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.
*
* @var array<int, string>
*/
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.
*
2023-12-12 12:25:45 +01:00
* @return void
*/
2023-12-12 12:25:45 +01:00
protected static function booted()
{
static::creating(function () {
InstantWin::removeCached();
Prize::removeCached();
});
static::updating(function () {
InstantWin::removeCached();
Prize::removeCached();
});
static::deleting(function () {
InstantWin::removeCached();
Prize::removeCached();
});
2023-12-12 12:25:45 +01:00
}
2023-12-05 12:33:25 +01:00
// * RELATIONSHIPS
/**
* BelongsTo Prize relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
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
}
/**
* One to one relation participation
*
2023-12-12 12:55:05 +01:00
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
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.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function activityLogs(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(ActivityLog::class);
}
2020-10-21 15:26:21 +02:00
}