将验证错误从laravel控制器返回到vue

时间:2019-02-09 18:17:01

标签: laravel validation vue.js

每个人,我都需要将此验证代码返回错误验证

  Validator::make($request->all(), [
    'title' => 'required|unique:posts|max:255',
    'body' => 'required',
 ])->validate();

我尝试过

 $validator =  Validator::make($request->all(), [
    'title' => 'required|unique:posts|max:255',
    'body' => 'required',
 ])->validate();

if ($validator->fails()) {
        return $this->sendError('error validation', $validator->errors());
    }

但对我没用

1 个答案:

答案 0 :(得分:0)

列表错误

$validator->messages();