首页 > 解决方案 > 翻译“给定的数据无效。” 在 Laravel 5.6 中

问题描述

如何翻译“给定的数据无效”。到 Laravel 5.6?谢谢

标签: laravelvalidation

解决方案


在中查找并替换该消息resources/lang/{lang_code}/validation

   'exists'               => 'The selected :attribute is invalid.',

在此处更改为您的语言而不是:attribute

或者

在文件的 render() 方法中添加以下行app\Exceptions\Handler.php

if ($exception instanceof ValidationException)
  return response()->json(['message' => 'Your error message here', 'errors' => $exception->validator->getMessageBag()], 422); //type your error code.

编码愉快~!:)


推荐阅读