'boolean', 'encryption_private_key' => 'encrypted', ]; protected static function booted(): void { static::creating(function (SignupChannel $channel): void { $channel->ensureEncryptionKeyPair(); if ($channel->channel_code !== null && $channel->channel_code !== '') { return; } do { $channel->channel_code = (string) Str::ulid(); } while (static::query()->where('channel_code', $channel->channel_code)->exists()); }); } public function ensureEncryptionKeyPair(): void { if (trim((string) $this->encryption_public_key) !== '' && trim((string) $this->encryption_private_key) !== '') { return; } $keys = ChannelEntryEncryption::generateKeyPair(); $this->encryption_algorithm = ChannelEntryEncryption::ALGORITHM; $this->encryption_public_key = $keys['public_key']; $this->encryption_private_key = $keys['private_key']; } public function competition(): BelongsTo { return $this->belongsTo(Competition::class); } public function firstSourceUsers(): HasMany { return $this->hasMany(User::class, 'first_channel_id'); } public function lastSourceUsers(): HasMany { return $this->hasMany(User::class, 'last_channel_id'); } public function applications(): HasMany { return $this->hasMany(Application::class, 'signup_channel_id'); } }