Laravel不会正确显示验证消息

时间:2016-01-20 09:36:29

标签: php validation laravel-5 laravel-5.1

在我的控制器里我有

public function store(Request $request) {
    $validator = Validator::make($request->all(), [
        "list_img" => "required",
        "ge_title" => "required|max:255"
    ]);

    if ($validator->fails()) {
        return redirect()->back()->withErrors($validator)->withInput();
    }

如果验证失败,我收到消息 -

validation.required

validation.required .....

而不是

需要ge_title

list_img是必需的

P.S。我的网站上有3种语言,我在资源/ lang中没有validation.php文件(如果有意义)

2 个答案:

答案 0 :(得分:1)

不是

  

$请求 - >查询 - >所有()

而不是

  

$请求 - >所有()

发帖或类似的东西?

答案 1 :(得分:1)

尝试在错误消息中添加第三个参数:

public function store(Request $request){
    $validator = Validator::make($request->all(), [
        "list_img" => "required",
        "ge_title" => "required|max:255"
    ], [
        "list_img.required" => "List img is required",
        "ge_title.required" => trans('errors.required'), //if you have multilang. then use trans function
        "ge_title.max" => trans('errors.max_title')
    ]);
    if ($validator->fails()){
        return redirect()->back()->withErrors($validator)->withInput();
    }
}