laravel5.3 中的表单验证错误提示问题.望大神解救


1.我首先在AppServiceProvider.php中注册了一个新的验证,
class AppServiceProvider extends ServiceProvider
{
/**
Bootstrap any application services.

@return void
/
public function boot()
{
Validator::extend('errorWord', function ($attribute, $value, $parameters, $validator) {
$text = [
'海贼王',
];
if (in_array($value, $text)) {
return false;
} else {
return true;
}

    });
}

2.控制器中:
class TestRequestController extends Controller
{
public function titleStore(Request $request)
{

  $validator = \Validator::make($request->all(), [
        'title' => 'required|errorWord',
    ]);
    if ($validator->fails()) {
        return redirect()->back()->withErrors($validator);
    }
}

3.页面:
<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>

<form action="{{ route('title.validator') }}" method="get">
{!! csrf_field() !!}
标题 :<input type="text" name="title">
@if ($errors->has('title'))
<span class="help-block">
<strong>{{ $errors->first('title') }}</strong>
</span>
@endif
<button type="submit">提交</button>
</form>
4.路由
Route::get('title/get/data/validator', 'TestRequestController@titleStore')->name('title.validator');

现在的问题是:
image http://forum.laravelacademy.org/assets/images/50-nCz28bAj31PiLdig.png

但是在验证:

image http://forum.laravelacademy.org/assets/images/50-kkJGWaTAXe3wMQaH.png

// lang/zh /validation.php
'title'=>[
'errorWord'=>'非法字眼',
],
'errorWord'=>'非法字眼',

没办法改成中文提示:
'custom' => [
/ 'attribute-name' => [
'rule-name' => 'custom-message',
],
/

    'title'=>[
        'errorWord'=>'非法字眼',
    ],
    'errorWord'=>'非法字眼',
],

'attributes' => [
'errorWord' => '非法字眼',
'title'=>'标题',
'content'=>'内容'
],

各种情况都试了,就是不能变成中文提示.求大神解救,到底要怎么改才可以....在5.2版本,我按照上面的来做,就能改成中文


Vote Vote Cancel Collect Collect Cancel

<< 上一篇: laravel怎么实现多条件模糊查询,而且前端选择查询的选项可以为空!

>> 下一篇: ab 测试laravel项目