*/ use HasFactory; protected $fillable = [ 'name', 'location', 'is_active', 'is_test', 'preview_token', ]; protected function casts(): array { return [ 'is_active' => 'boolean', 'is_test' => 'boolean', ]; } /** * @return HasMany */ public function playlists(): HasMany { return $this->hasMany(DisplayPlaylist::class); } /** * @return HasOne */ public function livePlaylist(): HasOne { return $this->hasOne(DisplayPlaylist::class) ->where('status', DisplayPlaylist::STATUS_PUBLISHED); } /** * @return HasOne */ public function draftPlaylist(): HasOne { return $this->hasOne(DisplayPlaylist::class) ->where('status', DisplayPlaylist::STATUS_DRAFT); } public function ensurePreviewToken(): string { if (! $this->preview_token) { $this->preview_token = Str::random(40); $this->save(); } return $this->preview_token; } public function rotatePreviewToken(): string { $this->preview_token = Str::random(40); $this->save(); return $this->preview_token; } public function clearPreviewToken(): void { if ($this->preview_token !== null) { $this->preview_token = null; $this->save(); } } }