Laravel 5.3验证错误消息未显示

时间:2016-10-12 13:09:34

标签: validation laravel-5.3

我有一个简单的验证规则列表:

$rules = [
        'vehicle_id'=> 'required|exists:vehicles,id',
        'ztl_id'=> 'required|exists:ztls,id',
        'user_id' => 'required|exists:users,id',
        'inizio' => 'required|date',
        'fine' => 'required|date|after:inizio',
        'percorso'=> 'required'
    ];
    $validator = $this->validate($request, $rules);
    dd("not until here");

如果在我的控制器上运行此代码,则会引发一般错误(如果验证失败),例如:"validation as fail"内部没有更多内容!

但是旅行槽类我已经在方法中找到了:

 public function validate(Request $request, array $rules, array $messages = [], array $customAttributes = [])
    {
        $validator = $this->getValidationFactory()->make($request->all(), $rules, $messages, $customAttributes);

        if ($validator->fails()) {

            dd($validator->errors()->getMessages());

            $this->throwValidationException($request, $validator);
        }
    }
ValidateRequest

dd($validator->errors()->getMessages());  所示:

  

数组:3   [“inizio”=>阵列:1   [       0 => “inizio领域是必需的。” ]
  “罚款”=>数组:1 [       0 => “需要精细的领域。” ]
  “percorso”=>数组:1 [       0 => “percorso领域是必需的。” ]]

这些都是我的错误,为什么throwValidationException($request, $validator);只显示一般情况而不是正确的mex?

0 个答案:

没有答案