['sometimes', 'nullable', 'string'], 'script_is_privileged' => ['sometimes', 'required', 'boolean'], 'script_entry' => ['sometimes', 'required', 'string'], 'script_container' => ['sometimes', 'required', 'string'], 'copy_script_from' => ['sometimes', 'nullable', 'integer'], ]; } public function update(Egg $egg, array $input): Egg { $attributes = Validator::validate($input, self::rules()); // Blank strings are null, as they are in a request, so a blank script or copy source is cleared. $attributes = array_map(fn (mixed $value): mixed => is_string($value) && blank($value) ? null : $value, $attributes); $copyFrom = $attributes['copy_script_from'] ?? null; if ($copyFrom !== null && ! Egg::query()->scriptSources()->whereKey($copyFrom)->exists()) { throw new InvalidCopyFromException(trans('exceptions.egg.invalid_copy_id')); } $egg->update($attributes); return $egg; } }