diff --git a/app/Http/Requests/Bo/MenuNodeData/UpdateMenuNodeDataRequest.php b/app/Http/Requests/Bo/MenuNodeData/UpdateMenuNodeDataRequest.php index eb0834a3..f445b206 100644 --- a/app/Http/Requests/Bo/MenuNodeData/UpdateMenuNodeDataRequest.php +++ b/app/Http/Requests/Bo/MenuNodeData/UpdateMenuNodeDataRequest.php @@ -27,14 +27,24 @@ class UpdateMenuNodeDataRequest extends FormRequest */ public function prepareForValidation(): void { - $this->merge([ - 'text' => str($this->input('text'))->value(), - 'link_target' => $this->boolean('link_target'), - 'link_status' => $this->boolean('link_status'), - 'picture_status' => $this->boolean('picture_status'), - ]); - $this->mergePicture('picture'); - $this->mergePicture('background_picture'); + if ($this->has('text')) { + $this->merge(['text' => str($this->input('text'))->value()]); + } + if ($this->has('link_target')) { + $this->merge(['link_target' => $this->boolean('link_target')]); + } + if ($this->has('link_status')) { + $this->merge(['link_status' => $this->boolean('link_status')]); + } + if ($this->has('picture_status')) { + $this->merge(['picture_status' => $this->boolean('picture_status')]); + } + if ($this->has('picture')) { + $this->mergePicture('picture'); + } + if ($this->has('background_picture')) { + $this->mergePicture('background_picture'); + } } /** @@ -45,24 +55,22 @@ class UpdateMenuNodeDataRequest extends FormRequest public function rules(): array { $rules = [ - 'title' => 'required|string|min:4|max:255', - 'text' => 'present|string|max:255', - 'link_url' => 'string|max:255', - 'link_title' => 'required|string|between:3,255', - 'link_target' => 'required|boolean', - 'link_status' => 'string|boolean', - 'picture' => 'string|max:255', - 'picture_alt' => 'string|between:3,255', - 'picture_title' => 'string|between:3,255', - 'picture_status' => 'string|boolean', - 'background_picture' => 'string|max:255', - 'background_picture_alt' => 'string|between:3,255', - 'background_picture_title' => 'string|between:3,255', + 'title' => 'sometimes|required|string|min:4|max:255', + 'text' => 'sometimes|required|string|max:255', + 'link_url' => 'sometimes|required|string|max:255', + 'link_title' => 'sometimes|required|string|between:3,255', + 'link_target' => 'sometimes|present|boolean', + 'link_status' => 'sometimes|present|boolean', + 'picture_alt' => 'sometimes|required|string|between:3,255', + 'picture_title' => 'sometimes|required|string|between:3,255', + 'picture_status' => 'sometimes|required|string|boolean', + 'background_picture_alt' => 'sometimes|required|string|between:3,255', + 'background_picture_title' => 'sometimes|required|string|between:3,255', ]; return \array_merge( $rules, - $this->pictureRules('picture', 180, 228, 180, 228), - $this->pictureRules('background_picture', 500, 231, 500, 231), + $this->pictureRules('picture', 180, 228, 180, 228, nullable: false, sometimes: true), + $this->pictureRules('background_picture', 500, 231, 500, 231, nullable: false, sometimes: true), ); } } diff --git a/app/Traits/Requests/HasPicture.php b/app/Traits/Requests/HasPicture.php index 7f83cfa5..17cbcbe3 100644 --- a/app/Traits/Requests/HasPicture.php +++ b/app/Traits/Requests/HasPicture.php @@ -49,6 +49,7 @@ trait HasPicture * @param integer|null $size * @param string|null $requiredWith * @param string|null $requiredWithout + * @param boolean $sometimes * @return array */ public function pictureRules( @@ -61,6 +62,7 @@ trait HasPicture ?int $size = null, ?string $requiredWith = null, ?string $requiredWithout = null, + bool $sometimes = false, ): array { $dimensions = (object)[ 'minWidth' => $minWidth ?? $this->minWidth, @@ -70,6 +72,7 @@ trait HasPicture ]; return [ $name => [ + $sometimes ? 'sometimes' : '', !$nullable ? 'required' : 'nullable', (strlen($requiredWith)) ? 'required_with:' . $requiredWith : '', (strlen($requiredWithout)) ? 'required_without:' . $requiredWithout : '', diff --git a/resources/ts/bo/components/ImageInputComponent.vue b/resources/ts/bo/components/ImageInputComponent.vue index 4372f73e..ed80a556 100644 --- a/resources/ts/bo/components/ImageInputComponent.vue +++ b/resources/ts/bo/components/ImageInputComponent.vue @@ -425,7 +425,7 @@