Laravel中validation验证 返回中文提示 全局设置的方法

更改 resources\lang 目录下边的 validation.php

<?php

return [

/*
|--------------------------------------------------------------------------
| Validation Language Lines
|--------------------------------------------------------------------------
|
| The following language lines contain the default error messages used by
| the validator class. Some of these rules have multiple versions such
| as the size rules. Feel free to tweak each of these messages here.
|
*/

'accepted'       => ':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 到 :max KB 之间',
  'string' => ':attribute 必须在 :min 到 :max 个字符之间',
  'array'  => ':attribute 必须在 :min 到 :max 项之间',
],
'boolean'       =>':attribute字符必须是 true 或false, 1 或 0 ',
'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 大小至少为 :min KB',
  '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 必须是 :size KB',
  'string' => ':attribute 必须是 :size 个字符',
  'array'  => ':attribute 必须包括 :size 项',
],
'string'        => ':attribute 必须是一个字符串',
'timezone'       => ':attribute 必须是个有效的时区.',
'unique'        => ':attribute 已存在',
'url'         => ':attribute 无效的格式',

/*
|--------------------------------------------------------------------------
| Custom Validation Language Lines
|--------------------------------------------------------------------------
|
| Here you may specify custom validation messages for attributes using the
| convention "attribute.rule" to name the lines. This makes it quick to
| specify a specific custom language line for a given attribute rule.
|
*/

'custom' => [
  'attribute-name' => [
    'rule-name' => 'custom-message',
  ],
],

/*
|--------------------------------------------------------------------------
| Custom Validation Attributes
|--------------------------------------------------------------------------
|
| The following language lines are used to swap attribute place-holders
| with something more reader friendly such as E-Mail Address instead
| of "email". This simply helps us make messages a little cleaner.
|
*/

'attributes' => [
  // 'name'     => '名字',
  // 'age'     => '年龄',
],

];

以上这篇Laravel中validation验证 返回中文提示 全局设置的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • laravel dingo API返回自定义错误信息的实例

    laravel 在使用了 dingo API 后,错误信息被dingo异常类接管了,返回信息变成了 : 要返回自定义的错误信息,就需要再把错误异常类接管回来(大概这个意思...) 方法: 在 app\Providers\AppServiceProvider.php 中的 boot() 方法 添加如下代码: app('api.exception')->register(function (\Exception $exception) { $request = Request::capture();

  • 如何优雅的使用 laravel 的 validator验证方法

    web 开发过程中经常会需要进行参数验证,laravel 中我们常用 validator 或者 request 这两种方法来进行验证,但是这两种验证都不是很方便进行自定义提示信息,自定义验证规则,所以下面来介绍一种很方便的用法: 新建抽象类 <?php namespace App\Http\Validators; use Validator; abstract class AbstractValidator { /** * Validator * * @var \Illuminate\Valid

  • Laravel框架表单验证格式化输出的方法

    最近在公司的项目开发中使用到了 laravel 框架,采用的是前后端开发的模式.接触过前后端开发模式的小伙伴应该都知道,后端返回的数据格式需要尽可能搞得保证一致性,这样前端在处理时也方便处理.我们先通过观看下面的两张接口返回的效果图吧,这样或许会更加的直观一些. laravel默认的输出格式(图一) 修改后的输出格式(图二) 或许通过上面两张图,你还是未看出有什么区别的话.这里我用文字描述一下吧. 这种情况是发生在laravel做表单验证的情况下发生的.前端向我后端接口发送一个POST请求时,发

  • Laravel中validation验证 返回中文提示 全局设置的方法

    更改 resources\lang 目录下边的 validation.php <?php return [ /* |-------------------------------------------------------------------------- | Validation Language Lines |-------------------------------------------------------------------------- | | The follo

  • spring security认证异常后返回中文提示的问题

    1.加载中文提示类 @Configuration public class ReloadMessageConfig { /** * 加载中文的认证提示信息 * * @return */ @Bean public ReloadableResourceBundleMessageSource messageSource() { ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessag

  • Kendo Grid editing 自定义验证报错提示的解决方法

    Kendo UI是一个强大的框架用于快速HTML5 UI开发.基于最新的HTML5.CSS3和JavaScript标准. Kendo UI包含了开发现代JavaScript开发所需要的所有一切,包括:强大的数据源,通用的拖拉(Drag-and-Drop)功能,模板,和UI控件. 今天开始就对项目里使用的kendo控件技巧做记录,有个别错误希望大家不吝指出,谢谢. 首先就是Grid控件编辑是,验证错误时弹出的提示居然是中文加字段名字,如下图.抓狂啊!!请问这样的低级的提示能拿得出手吗? 这样的提示

  • Laravel自定义 封装便捷返回Json数据格式的引用方法

    一般返回数据格式 return response()->json(['status' => 'success','code' => 200,'message' => '关注成功']); return response()->json(['status' => 'fail','code' => 500,'error' => '关注失败',]); 基类控制器 <?php namespace App\Http\Controllers; use Illumin

  • ASP.NET中为GridView添加删除提示框的方法

    本文实例讲述了ASP.NET中为GridView添加删除提示框的方法.分享给大家供大家参考.具体分析如下: 在GridView中我们可以直接添加一个CommandField删除列来删除某行信息.但为了避免误操作引起的误删除,在删除操作者让操作者再确认下,完后再进行删除. 首先我们给我们的GridView 添加一个模板列,如下: 以下是引用片段: <ASP:TemplateField HeaderText="Delete" ShowHeader="False"&

  • laravel 实现登陆后返回登陆前的页面方法

    最近做了一个项目,需要用户登录后,返回登陆前的页面. 一般的逻辑是,用户访问某个页面,判断未登录,跳转到登陆界面,登陆成功后,返回访问前的页面. 按照laravel的一般情况来做: //头部引入 use URL //登陆成功后执行 return redirect(URL::previous()); 结果发现跳转的是登陆页面,感觉很奇怪,最后发现是,我的登陆提交是一个新的方法,导致要返回之前的页面,需要返回2次才可以. 解决,在跳转到登陆界面的时候,将上次的网址记录,登陆成功后,跳转到记录的网址,

  • termux中matplotlib无法显示中文问题的解决方法

    问题背景 在开始正文之前,感谢用户名为怜索的朋友送给了我的博客2021年的第一个赞! import numpy as np import matplotlib import matplotlib.pyplot as plt import os matplotlib.rcParams['xtick.direction'] = 'in' matplotlib.rcParams['ytick.direction'] = 'in' plt.rcParams['axes.unicode_minus'] =

  • ASP.NET中Validation验证控件正则表达式特殊符号的说明

    RegularExpressionValidator控件表达式说明: 方括号"[ ]"用与定义可接受的字符.[abc123] 表示控件只能接受 a,b,c,1,2,3 这6个字符: 反集合符号 " ^ "用于定义不可以接受的字符.[^a-h] 表示控件除了 a 到 h 8个字符外,都可以接受: 花括号"{ }"定义必须输入的字符个数.{6}表示只能输入6个字符 : {6,}表示必须输入6个以上,无上限 : {2,6} 表示必须输入2至6个字符:但

  • MyBatis中insert操作返回主键的实现方法

    在使用MyBatis做持久层时,insert语句默认是不返回记录的主键值,而是返回插入的记录条数:如果业务层需要得到记录的主键时,可以通过配置的方式来完成这个功能 针对Sequence主键而言,在执行insert sql前必须指定一个主键值给要插入的记录,如Oracle.DB2,可以采用如下配置方式: <insert id="add" parameterType="vo.Category"> <selectKey resultType="

  • Laravel中重写资源路由自定义URL的实现方法

    前言 本文主要给大家介绍了关于Laravel中重写资源路由自定义URL的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍: 重写原因 近期在使用Laravel开发项目过程中,为了简化路由代码使用了Laravel的资源路由,Route::resource('photo', 'PhotoController'); 在默认情况下,Laravel生成的路由表如下: 动作 路径 Action 路由名称 GET /photo index photo.index GET /photo/c

随机推荐