laravel 验证器 Validator::make只显示第一个错误
以下为方法
```
public function index(Request $request)
{
if ($request->isMethod('post')){
$validator = Validator::make($request->all(), [
'username'=>'required|min:4|max:16',
'password'=>'required!min:6|max:20',
//..........
]);
if($validator->fails()){
return response()->json(['code'=>'201','msg'=>$validator->errors()->first()]);
}
}else{
return view('home.login.reg');
}
}
```
以下为try catch
```
$params = $request->all();
try{
$validator = Validator::make($params, [
'phone' => 'required',
'code' => 'required',
]);
if ($validator->fails()) {
$error = $validator->errors()->first();
throw new \Exception($error);
}
}catch (\Exception $e){
return $this->jsonError($e->getMessage());
}
```