app/Exceptions/Handler.php
/**
     * Render an exception into an HTTP response.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Exception $exception
     * @return \Illuminate\Http\Response
     */
Render an exception into an HTTP response.
Render an exception into an HTTP response .
public function render($request, Exception $exception)
    {
        if ($request->ajax()) {
            if ($exception instanceof ValidationException) {
                return response()->json(['status' => 1, 'msg' => '验证失败', 'data' => $exception->validator->messages()],422);
            }
            return parent::render($request,$exception);
        }
        if ($exception instanceof LoginException){
            $data = ['status' => $exception->getCode(),'msg' => $exception->getMessage()];
            return response()->json($data,401);
        }elseif ($exception instanceof MyValidateException){
            $data = ['status' => $exception->getCode(),'msg' => $exception->getMessage()];
            return response()->json($data,401);
        }
        return parent::render($request, $exception);
    }
public function render ( $ request , Exception $ exception ) { if ( $ request -> ajax ( ) ) { if ( $ exception instanceof ValidationException ) { return response ( ) -> json ( [ 'status' => 1 , 'msg' => '验证失败', 'data' > $exc pt o n->valida to r->messag es ()],422) ; } return parent :: render ( $ request , $ exception ) ; } if ( $ exception instanceof LoginException ) { $ data = [ 'status' => $ exception -> getCode ( ) , 'msg' => $ exception -> getMessage ( ) ] ; return response ( ) -> json ( $ data , 401 ) ; } elseif ( $ exception instanceof MyValidateException ) { $ data = [ 'status' => $ exception -> getCode ( ) , 'msg' => $ exception -> getMessage ( ) ] ; return response ( ) -> json ( $ data , 401 ) ; } return parent :: render ( $ request , $ exception ) ; }
Render an exception into an HTTP response.
Render an exception into an HTTP response .
// 判断响应数据json // 是否是表单验证的异常 // 返回响应数据json // 如果不是表单验证错误，是什么错误就返回什么错误 // 接口判断 // 1账号有误