38 lines
952 B
PHP
38 lines
952 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/** What a player is told about a battle or a support arriving. The payload is a snapshot. */
|
|
class Report extends Model
|
|
{
|
|
public const ATTACK = 'attack';
|
|
|
|
public const DEFENSE = 'defense';
|
|
|
|
public const SUPPORT = 'support';
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.v';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'payload' => 'array',
|
|
'happened_at' => 'immutable_datetime',
|
|
'read_at' => 'immutable_datetime',
|
|
];
|
|
}
|
|
|
|
/** @param array<string, mixed> $payload */
|
|
public static function write(?int $playerId, string $type, array $payload, CarbonImmutable $at): void
|
|
{
|
|
if ($playerId !== null) {
|
|
self::create(['player_id' => $playerId, 'type' => $type, 'payload' => $payload, 'happened_at' => $at]);
|
|
}
|
|
}
|
|
}
|