errors()->messages() as $items) { foreach ($items as $item) { $messageList[] = $item; } } $message = implode('
', $messageList); $format = json_encode(['message' => $message]); throw (new ValidationException($validator, new Response($format, 422))) ->errorBag($this->errorBag) ->redirectTo($this->getRedirectUrl()); } // public function messages() // { // return [ // 'required' => ':attribute不能为空', // 'in' => ':attribute必须是以下取值: :values', // 'numeric' => ':attribute必须是数字', // 'max' => [ // 'numeric' => ':attribute 应小于:max ', // 'file' => ':attribute 应小于:max kb', // 'string' => ':attribute应小于 :min 位', // 'array' => ':attribute应大于 :min 列表', // ], // 'min' => [ // 'numeric' => ':attribute应大于 :min ', // 'file' => ':attribute应大于 :min kb', // 'string' => ':attribute应大于 :min 位', // 'array' => ':attribute应大于 :min 列表', // ], // 'unique' => ':attribute 已存在', // 'array' => ':attribute应为列表' // ]; // } }