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

Richardxx 2019-10-22

  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;
    }

相关推荐

mmywcoco / 0评论 2020-06-06