'required|date_format:Y', 'crop_id' => 'required|integer|min:0', 'flows' => 'required|array|min:1', 'flows.*' => 'required_array_keys:flow_name,sale', ]; } public function messages() { $messages = [ 'time_year' => '请选择年份', 'crop_id' => '请选择农作物', 'flows' => '请填写基地以及产值信息', 'flows.*.required_array_keys' => '请填写完整基地以及产值信息', ]; return $messages; } protected function failedValidation(Validator $validator) { $error = $validator->errors()->all(); throw new HttpResponseException(response()->json(['data' => [], 'code' => 400, 'message' => $error[0]])); } }