*/ use HasFactory; public $guarded = []; public $casts = [ 'data' => 'json', 'last_remembered_at' => 'datetime', ]; /** * @return BelongsTo */ public function form(): BelongsTo { return $this->belongsTo(Form::class); } /** * @return HasMany */ public function children(): HasMany { return $this->hasMany(self::class, 'parent_id'); } /** * @param Builder $query * @return Builder */ public function scopeWithFilter(Builder $query, ParticipantFilterScope $filter): Builder { return $filter->apply($query); } /** * @return BelongsTo */ public function member(): BelongsTo { return $this->belongsTo(Member::class); } public function getFields(): FieldCollection { return FieldCollection::fromRequest($this->form, $this->data); } public function getConfig(): FormConfigData { return tap($this->form->config, function ($config) { $config->sections->each(function ($section) { $section->fields->each(function ($field) { $field->value = $this->getFields()->find($field)->value; }); }); }); } public function sendConfirmationMail(): void { if (!$this->getFields()->getMailRecipient()) { return; } Mail::to($this->getMailRecipient())->queue(new ConfirmRegistrationMail($this)); } public function preventableLayout(): string { return 'mail.prevention.prevention-remember-participant'; } /** * @inheritdoc */ public function preventions(): array { return $this->member?->preventions($this->form->from) ?: []; } public function getMailRecipient(): stdClass { return $this->getFields()->getMailRecipient(); } public function preventableSubject(): string { return 'Nachweise erforderlich für deine Anmeldung zu ' . $this->form->name; } }