key === "Button1" || $this->key === "Button2" || $this->key === "Button3" || $this->key === "ShowIsActive" ) { return auth('backend')->check(); } else { return (auth('backend')->check() && Auth::user()->role === UserRolesEnum::admin()->value); } } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation() { 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() { 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.FoundInExtendedClassBeforeLastUsed 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', true, 100, 100, 1920, 1200); } else { return ['value' => 'required|string|min:1']; } //end if } /** * Get custom attributes for validator errors. * * @return array */ public function attributes() { return [ 'key' => \trans('clé'), 'value' => \trans('valeur'), 'type' => \trans('type'), ]; } }