confirm(); * $pending = DnsTicket::pending()->get(); */ class DnsTicket extends Model { use \Core\Tenant\Concerns\BelongsToWorkspace; protected bool $workspaceContextRequired = false; protected $fillable = [ 'ticket_id', 'name', 'status', 'tx_id', 'records', 'address', 'workspace_id', 'comment', ]; protected $casts = [ 'records' => 'array', ]; protected static function booted(): void { static::creating(function (self $ticket) { if (empty($ticket->ticket_id)) { $ticket->ticket_id = bin2hex(random_bytes(6)); } }); } public function scopePending($query) { return $query->where('status', 'pending'); } public function scopeQueued($query) { return $query->where('status', 'queued'); } public function confirm(): void { $this->update(['status' => 'confirmed']); } public function fail(): void { $this->update(['status' => 'failed']); } /** * Open a new DNS change ticket. */ public static function open(string $name, array $records, ?string $txId = null, ?string $address = null, ?string $comment = null): self { return static::create([ 'name' => $name, 'status' => $txId ? 'pending' : 'queued', 'tx_id' => $txId, 'records' => $records, 'address' => $address, 'comment' => $comment, ]); } }