key === "Button1" || $this->key === "Button2" || $this->key === "Button3" || $this->key === "ShowIsActive" ) { return Gate::check('update', $this->route('setting')); } else { /** @var \App\Models\User $user */ $user = Auth::guard('backend')->user(); return $user->can('isAdmin'); } } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation(): void { if ($this->key === "ShowIsActive") { $this->merge(['value' => intval($this->value) ? "true" : "false"]); } elseif ( $this->key === "Button1" || $this->key === "Button2" || $this->key === "Button3" ) { $this->merge(['value' => $this->value === "0" ? null : $this->value]); } elseif ( $this->key === "SquaredLogo" || $this->key === "RectangleLogo" || $this->key === "BackgroundImage" || $this->key === "HomeButtonImage" ) { $this->mergePicture('value'); } } /** * Get the validation rules that apply to the request. * * @return array */ public function rules(): array { if ( $this->key === "Button1" || $this->key === "Button2" || $this->key === "Button3" ) { $buttonsNullable = 0; $buttons = Setting::where('key', 'Button1') ->orWhere('key', 'Button2') ->orWhere('key', 'Button3') ->get(); foreach ($buttons as $button) { if ($button->value === null) { if ($button->key !== $this->key) { $buttonsNullable++; } }; } return [ 'value' => [ //phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed function ($attribute, $value, $fail) use ($buttonsNullable) { if (!isset($value) && $buttonsNullable >= 2) { $fail(\trans('Au moins 1 bouton doît être défini.')); } } ] ]; } elseif ( $this->key === "SquaredLogo" || $this->key === "RectangleLogo" || $this->key === "BackgroundImage" || $this->key === "HomeButtonImage" ) { return $this->pictureRules('value', 100, 100, 1920, 1200, true); } else { return ['value' => 'required|string|min:1']; } //end if } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'key' => \trans('validation.custom.key'), 'value' => \trans('validation.custom.value'), 'type' => \trans('validation.custom.type'), ]; } }