Php 如何通过扩展Laravel 5中的Validator类来添加自定义错误消息?

Php 如何通过扩展Laravel 5中的Validator类来添加自定义错误消息?,php,regex,laravel,laravel-5,laravel-validation,Php,Regex,Laravel,Laravel 5,Laravel Validation,我想验证alpha_破折号(字母表和空格),下面的代码工作正常 Validator::extend('alpha_spaces', function($attribute, $value) { return preg_match("/^[a-z0-9 .\-]+$/i", $value); }); 但它给出的错误对用户不友好: validation.alpha_spaces 如何更改此消息 这就是它所使用的方法 public function create(Request $requ

我想验证alpha_破折号(字母表和空格),下面的代码工作正常

Validator::extend('alpha_spaces', function($attribute, $value)
{
    return preg_match("/^[a-z0-9 .\-]+$/i", $value);
});
但它给出的错误对用户不友好:

validation.alpha_spaces
如何更改此消息

这就是它所使用的方法

public function create(Request $request)
{

    $this->validate($request, [
        'title' => 'required|alpha_spaces|max:255',
    ]);


}

谢谢

只需将自定义错误消息作为数组元素添加到
resources/lang/xx/validation.php

'alpha_spaces' => 'The :attribute may only contain letters, numbers and spaces.',

阅读更多信息:

只需将自定义错误消息作为数组元素添加到
resources/lang/xx/validation.php

'alpha_spaces' => 'The :attribute may only contain letters, numbers and spaces.',

阅读更多信息:

只需将自定义错误消息作为数组元素添加到
resources/lang/xx/validation.php

'alpha_spaces' => 'The :attribute may only contain letters, numbers and spaces.',

阅读更多信息:

只需将自定义错误消息作为数组元素添加到
resources/lang/xx/validation.php

'alpha_spaces' => 'The :attribute may only contain letters, numbers and spaces.',
阅读更多: