Laravel自定义验证消息

时间:2017-02-10 11:36:00

标签: php laravel validation laravel-5 laravel-5.4

我正在使用laravel 5.4进行自定义表单验证。但为什么不显示自定义错误消息?

   Validator::extend('myCustomeValidator', function ($attribute, $value, $parameters, $validator) {
        //some code here
        return false;
    });

    return Validator::make($data, [
        'myField' => 'myCustomeValidator',
    ]);

并将以下内容添加到文件中:ressources\lang\en\validation.php,如文档所述:

    'custom' => [
        'myField' => [
            'myCustomeValidator' => 'You made an error.',
        ],
    ],

错误被正确触发但是我没有自定义错误消息:

  

validation.my_custome_validator

我错过了什么?

1 个答案:

答案 0 :(得分:2)

您需要使用自定义验证规则的 snake-cased 名称。以下应该是诀窍:

$User = "SERVER-NAME\AdminUser"
$Password = "Password"

$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("x:", "\\SERVER-NAME\TestFolder", $false, $User, $Password)
Copy-Item -Path "D:\Path\To\Copy\From" -Destination "x:\" -Recurse -Force -PassThru
$net.RemoveNetworkDrive("x:", 0)