都是这个方法惹的祸,在基类中重写这个方法就行了 

laravel Validate验证失败后跳转到首页的问题

 在baseController中加入以下代码就ojbk了

/**
     * 统一返回数据格式
     * @param $data
     * @return false|string
     */
    protected function json($data){
        header('Content-type:text/json');
        exit(json_encode($data));
    }
 
    protected function throwValidationException(Request $request , $validator){
        foreach ((array)$validator->errors() as $val){
            if (is_array($val)){
                foreach ($val as $k => $v){
                    $this->json(['code' => 400 , 'msg' => $v[0] , 'data' => []]);
                }
            }
        }
    }
 

相关文章:

  • 2022-12-23
  • 2022-01-25
  • 2021-05-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2021-06-21
猜你喜欢
  • 2021-07-18
  • 2021-11-21
  • 2021-12-21
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
  • 2021-06-15
相关资源
相似解决方案