laravel 返回ajax请求错误信息 第二种

  public function login(Request $request)
    {
        $info = Validator::make($request->all(), [
            'username' => 'required',
            'password' => 'required',
        ],[
            'username.required' => '用户名必须填写',
            'password.required' => '密码必须填写',
        ]);

        if ($info->fails()) {
            //返回json数据
            return response()->json(['code'=>"201","msg"=>$info->errors()->first()]);
        }

        // dd($info->errors()->first());
        // return $info;
    }

猜你喜欢

转载自www.cnblogs.com/zjj1990/p/11721170.html