如何让Lumen使用默认验证消息?

时间:2017-05-26 09:01:23

标签: lumen

我在Lumen中有一个标准文件夹用于错误消息,类似于Laravel。问题是来自那里的消息没有被使用。如何让Lumen使用我的翻译格式化消息?

现在当我转储$ validator-> errors()时,它不会格式化消息。

MessageBag {#223
  #messages: array:4 [
    "surname" => array:1 [
      0 => "validation.required"
    ]
    "mobile" => array:1 [
      0 => "validation.required"
    ]
    "password" => array:1 [
      0 => "validation.min.string"
    ]
    "email" => array:1 [
      0 => "validation.email"
    ]
  ]
  #format: ":message"
}

1 个答案:

答案 0 :(得分:4)

基本上translator缺少应在此实例解析之前配置的语言环境配置。将其添加到您的:config/app.php

/*
|--------------------------------------------------------------------------
| Application Locale Configuration
|--------------------------------------------------------------------------
|
| The application locale determines the default locale that will be used
| by the translation service provider. You are free to set this value
| to any of the locales which will be supported by the application.
|
*/
'locale' => env('APP_LOCALE', 'en'),