Laravel修改验证提示信息为中文的示例
1.覆盖提示信息:
打开resource/lang/en/validation.php注释掉英文提示信息
将下面的提示信息覆盖英文提示信息
':attribute必须接受', 'active_url'=>':attribute必须是一个合法的URL', 'after'=>':attribute必须是:date之后的一个日期', 'after_or_equal'=>':attribute必须是:date之后或相同的一个日期', 'alpha'=>':attribute只能包含字母', 'alpha_dash'=>':attribute只能包含字母、数字、中划线或下划线', 'alpha_num'=>':attribute只能包含字母和数字', 'array'=>':attribute必须是一个数组', 'before'=>':attribute必须是:date之前的一个日期', 'before_or_equal'=>':attribute必须是:date之前或相同的一个日期', 'between'=>[ 'numeric'=>':attribute必须在:min到:max之间', 'file'=>':attribute必须在:min到:maxKB之间', 'string'=>':attribute必须在:min到:max个字符之间', 'array'=>':attribute必须在:min到:max项之间', ], 'boolean'=>':attribute字符必须是true或false', 'confirmed'=>':attribute二次确认不匹配', 'date'=>':attribute必须是一个合法的日期', 'date_format'=>':attribute与给定的格式:format不符合', 'different'=>':attribute必须不同于:other', 'digits'=>':attribute必须是:digits位.', 'digits_between'=>':attribute必须在:min和:max位之间', 'dimensions'=>':attribute具有无效的图片尺寸', 'distinct'=>':attribute字段具有重复值', 'email'=>':attribute必须是一个合法的电子邮件地址', 'exists'=>'选定的:attribute是无效的.', 'file'=>':attribute必须是一个文件', 'filled'=>':attribute的字段是必填的', 'image'=>':attribute必须是jpeg,png,bmp或者gif格式的图片', 'in'=>'选定的:attribute是无效的', 'in_array'=>':attribute字段不存在于:other', 'integer'=>':attribute必须是个整数', 'ip'=>':attribute必须是一个合法的IP地址。', 'json'=>':attribute必须是一个合法的JSON字符串', 'max'=>[ 'numeric'=>':attribute的最大长度为:max位', 'file'=>':attribute的最大为:max', 'string'=>':attribute的最大长度为:max字符', 'array'=>':attribute的最大个数为:max个.', ], 'mimes'=>':attribute的文件类型必须是:values', 'min'=>[ 'numeric'=>':attribute的最小长度为:min位', 'file'=>':attribute大小至少为:minKB', 'string'=>':attribute的最小长度为:min字符', 'array'=>':attribute至少有:min项', ], 'not_in'=>'选定的:attribute是无效的', 'numeric'=>':attribute必须是数字', 'present'=>':attribute字段必须存在', 'regex'=>':attribute格式是无效的', 'required'=>':attribute字段是必须的', 'required_if'=>':attribute字段是必须的当:other是:value', 'required_unless'=>':attribute字段是必须的,除非:other是在:values中', 'required_with'=>':attribute字段是必须的当:values是存在的', 'required_with_all'=>':attribute字段是必须的当:values是存在的', 'required_without'=>':attribute字段是必须的当:values是不存在的', 'required_without_all'=>':attribute字段是必须的当没有一个:values是存在的', 'same'=>':attribute和:other必须匹配', 'size'=>[ 'numeric'=>':attribute必须是:size位', 'file'=>':attribute必须是:sizeKB', 'string'=>':attribute必须是:size个字符', 'array'=>':attribute必须包括:size项', ], 'string'=>':attribute必须是一个字符串', 'timezone'=>':attribute必须是个有效的时区.', 'unique'=>':attribute已存在', 'url'=>':attribute无效的格式', /* |-------------------------------------------------------------------------- |CustomValidationLanguageLines |-------------------------------------------------------------------------- | |Hereyoumayspecifycustomvalidationmessagesforattributesusingthe |convention"attribute.rule"tonamethelines.Thismakesitquickto |specifyaspecificcustomlanguagelineforagivenattributerule. | */ 'custom'=>[ 'attribute-name'=>[ 'rule-name'=>'custom-message', ], ], /* |-------------------------------------------------------------------------- |CustomValidationAttributes |-------------------------------------------------------------------------- | |Thefollowinglanguagelinesareusedtoswapattributeplace-holders |withsomethingmorereaderfriendlysuchasE-MailAddressinstead |of"email".Thissimplyhelpsusmakemessagesalittlecleaner. | */ 'attributes'=>[ //'name'=>'名字', //'age'=>'年龄', ], ];
2.安装中文信息提示包
composerrequire"overtrue/laravel-lang:~3.0"
注册服务提供者:config/app.php
'providers'=>[ //Illuminate\Translation\TranslationServiceProvider::class, Overtrue\LaravelLang\TranslationServiceProvider::class, ]
修改语言:config/app.php
'locale'=>'zh-CN',
以上这篇Laravel修改验证提示信息为中文的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。