Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 28s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
41 lines
810 B
PHP
41 lines
810 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* Remembers what the alert scanner has already seen so each event notifies once.
|
|
*/
|
|
class AlertState extends Model
|
|
{
|
|
public $incrementing = false;
|
|
|
|
protected $primaryKey = 'key';
|
|
|
|
protected $keyType = 'string';
|
|
|
|
protected $fillable = ['key', 'state'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['state' => 'array'];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>|null
|
|
*/
|
|
public static function read(string $key): ?array
|
|
{
|
|
return static::find($key)?->state;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $state
|
|
*/
|
|
public static function write(string $key, array $state): void
|
|
{
|
|
static::updateOrCreate(['key' => $key], ['state' => $state]);
|
|
}
|
|
}
|