value; } $details = Validator::make($details, [ 'block_purpose' => ['nullable', Rule::enum(BlockedPeriodPurpose::class)], 'block_note' => ['nullable', 'string', 'max:255'], 'is_private' => ['sometimes', 'boolean'], ])->validate(); if (($details['is_private'] ?? false) && $originId !== null) { throw ValidationException::withMessages(['origin_channel_id' => 'Privat und ein externer Buchungskanal können nicht gleichzeitig gewählt werden.']); } DB::transaction(function () use ($occupation, $kind, $originId, $details): void { $record = BlockedPeriod::query()->whereKey($occupation->id)->lockForUpdate()->firstOrFail(); if (! in_array($record->source, ['channel', 'email'], true) || $record->is_representation) { throw ValidationException::withMessages(['occupation_kind' => 'Nur eigenständige Portalereignisse können hier eingeordnet werden.']); } if ($originId !== null && ! Channel::query()->where('property_id', $record->property_id)->whereKey($originId)->exists()) { throw ValidationException::withMessages(['origin_channel_id' => 'Der Ursprungskanal muss zur selben Wohnung gehören.']); } $record->forceFill([ 'occupation_kind' => $kind, 'origin_channel_id' => $originId, 'is_private' => $details['is_private'] ?? false, 'block_purpose' => $kind === OccupationKind::Block ? (array_key_exists('block_purpose', $details) ? $details['block_purpose'] : $record->block_purpose) : null, 'block_note' => $kind === OccupationKind::Block ? (array_key_exists('block_note', $details) ? $details['block_note'] : $record->block_note) : null, ])->save(); }); } }