php – Laravel验证自定义消息

前端之家收集整理的这篇文章主要介绍了php – Laravel验证自定义消息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我面临着一个问题,laravel定制验证信息,这里是我有的:
$rules = [
    'first_name'            => 'required|alpha|min:2','last_name'             => 'required|alpha|min:2','email'                 => 'required|email|unique:users,email,' . Input::get('id') . ',id','password'              => 'alpha_num|between:6,12|confirmed','password_confirmation' => 'alpha_num|between:6,12','address'               => 'regex:/^[a-z0-9- ]+$/i|min:2','city'                  => 'alpha|min:2','state'                 => 'alpha|min:2|max:2','zip'                   => 'numeric|min:5|max:5','phone'                 => 'regex:/^\d{3}\-\d{3}\-\d{4}$/',];
$messages = [
    'unique' => 'The :attribute already been registered.','regex'  => 'The :attribute number has to be formated : xxx-xxx-xxxx.',];

现在如果地址或电话号码有问题,因为它们都具有正则表达式验证规则,错误信息将是:必须形成:属性号码:xxx-xxx-xxxx,我如何为每个不同的定制消息一个?

这样做的方法,而不是使用’regex’,使用’regex.phone’
$rules = [
    'first_name'            => 'required|alpha|min:2',];
$messages = [
    'unique'        => 'The :attribute already been registered.','phone.regex'   => 'The :attribute number is invalid,accepted format: xxx-xxx-xxxx','address.regex' => 'The :attribute format is invalid.',];

猜你在找的Laravel相关文章