route('general_setting')); } /** * Prepare the data for validation. * * @return void */ public function prepareForValidation(): void { /** @var \App\Models\GeneralSetting $generalSettingModel */ $generalSettingModel = $this->route('general_setting'); if ($generalSettingModel->type === SettingsType::hotNews) { $this->mergePicture('picture'); $this->merge([ 'value' => [ 'picture_alt' => $this->input('picture_alt'), 'picture_title' => $this->input('picture_title'), 'picture' => $this->input('picture_title'), 'text' => $this->input('text') ] ]); return; } $this->merge([ 'value' => json_decode($this->input('jsonValue', '[]')) ]); } /** * Get the validation rules that apply to the request. * * @return array|string> */ public function rules(): array { /** @var \App\Models\GeneralSetting $generalSettingModel */ $generalSettingModel = $this->route('general_setting'); if ($generalSettingModel->type === SettingsType::hotNews) { $rules = [ 'text' => 'required|string|between:3,255', 'picture_alt' => 'required|string|between:3,255', 'picture_title' => 'required|string|between:3,255', ]; return \array_merge( $rules, $this->pictureRules('picture', 200, 150, 200, 150, false), ); } else { return [ 'jsonValue' => 'required|json', 'value' => 'required' ]; } } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'value' => trans('validation.custom.value') ]; } }