*/ protected $fillable = [ 'declaration_id', 'token', 'email', 'expires_at', 'used_at', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'expires_at' => 'datetime', 'used_at' => 'datetime', ]; } /** * Boot the model. */ protected static function boot(): void { parent::boot(); static::creating(function (DeclarationInvitation $invitation) { if (empty($invitation->token)) { $invitation->token = Str::uuid()->toString(); } }); } /** * Get the declaration that owns the invitation. * * @return BelongsTo */ public function declaration(): BelongsTo { return $this->belongsTo(Declaration::class); } /** * Check if the invitation is valid (not expired, not used). */ public function isValid(): bool { if ($this->used_at !== null) { return false; } return $this->expires_at->isFuture(); } }