Live Show data model + workflow
This commit is contained in:
@@ -23,6 +23,7 @@ class Event extends Model
|
||||
'is_active' => 'boolean',
|
||||
'name' => 'array',
|
||||
'description' => 'array',
|
||||
'live_show_token_rotated_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
@@ -152,6 +153,29 @@ class Event extends Model
|
||||
return $this->eventPackage->canUploadPhoto();
|
||||
}
|
||||
|
||||
public function ensureLiveShowToken(): string
|
||||
{
|
||||
if (is_string($this->live_show_token) && $this->live_show_token !== '') {
|
||||
return $this->live_show_token;
|
||||
}
|
||||
|
||||
return $this->rotateLiveShowToken();
|
||||
}
|
||||
|
||||
public function rotateLiveShowToken(): string
|
||||
{
|
||||
do {
|
||||
$token = bin2hex(random_bytes(32));
|
||||
} while (self::query()->where('live_show_token', $token)->exists());
|
||||
|
||||
$this->forceFill([
|
||||
'live_show_token' => $token,
|
||||
'live_show_token_rotated_at' => now(),
|
||||
])->save();
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
public function getSettingsAttribute($value): array
|
||||
{
|
||||
if (is_array($value)) {
|
||||
|
||||
Reference in New Issue
Block a user