2020-10-21 15:26:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
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
|
|
|
|
2023-08-24 13:00:43 +02:00
|
|
|
/**
|
|
|
|
|
* InstantWin.
|
|
|
|
|
*
|
2023-12-08 15:39:13 +01:00
|
|
|
* @property \Illuminate\Support\Carbon $available_at When the instant win will be available.
|
2023-08-24 13:00:43 +02:00
|
|
|
*
|
2023-11-21 12:28:09 +01:00
|
|
|
* @property-read \App\Models\Prize $prize Associated prize.
|
2023-08-24 13:00:43 +02:00
|
|
|
* @property-read \App\Models\Participation $participation Associated participation.
|
|
|
|
|
*/
|
2020-10-21 15:26:21 +02:00
|
|
|
class InstantWin extends Model
|
|
|
|
|
{
|
2023-12-12 12:25:45 +01:00
|
|
|
use IsCachedAsCollection;
|
|
|
|
|
|
2022-01-11 12:39:28 +01:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
2022-01-11 12:39:28 +01:00
|
|
|
/**
|
|
|
|
|
* The relations to eager load on every query.
|
|
|
|
|
*
|
2024-01-19 12:21:15 +01:00
|
|
|
* @var array<string>
|
2022-01-11 12:39:28 +01:00
|
|
|
*/
|
2020-10-21 15:26:21 +02:00
|
|
|
protected $with = ['prize'];
|
|
|
|
|
|
2023-12-12 12:25:45 +01:00
|
|
|
// * EVENTS
|
|
|
|
|
|
2022-01-11 12:39:28 +01:00
|
|
|
/**
|
2023-12-12 12:25:45 +01:00
|
|
|
* Perform any actions required after the model boots.
|
2022-01-11 12:39:28 +01:00
|
|
|
*
|
2023-12-12 12:25:45 +01:00
|
|
|
* @return void
|
2022-01-11 12:39:28 +01:00
|
|
|
*/
|
2023-12-12 12:25:45 +01:00
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::creating(fn () => self::removeCached());
|
|
|
|
|
static::updating(fn () => self::removeCached());
|
|
|
|
|
static::deleting(fn () => self::removeCached());
|
|
|
|
|
}
|
2022-01-11 12:39:28 +01:00
|
|
|
|
2023-12-05 12:33:25 +01:00
|
|
|
// * RELATIONSHIPS
|
|
|
|
|
|
2022-01-11 12:39:28 +01:00
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
{
|
2022-01-11 12:39:28 +01:00
|
|
|
return $this->belongsTo(Prize::class, 'prize_id');
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|
2020-11-04 11:49:43 +01:00
|
|
|
|
2022-01-11 12:39:28 +01:00
|
|
|
/**
|
|
|
|
|
* One to one relation participation
|
|
|
|
|
*
|
2023-12-12 12:55:05 +01:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2022-01-11 12:39:28 +01:00
|
|
|
*/
|
2023-12-12 12:55:05 +01:00
|
|
|
public function participation(): BelongsTo
|
2021-08-18 17:08:02 +02:00
|
|
|
{
|
2022-01-11 12:39:28 +01:00
|
|
|
return $this->belongsTo(Participation::class);
|
2020-11-04 11:49:43 +01:00
|
|
|
}
|
2020-10-21 15:26:21 +02:00
|
|
|
}
|