request = $request; $this->params = $request->input(); $this->initialize(); } protected function initialize() { $this->request->attributes->add([ 'rules' => $this->rules[explode('@', $this->request->route()->getActionName())[1]] ?? [], 'attributes' => $this->model->attrs, ]); $this->middleware('param_verify'); } protected function success($data = [], $msg = '请求成功', $code = 200) { if($data instanceof ResourceCollection){ $response = ['code' => $code, 'msg' => $msg] + $data->toArray($this->request); } else { $response = ['code' => $code, 'msg' => $msg, 'data' => $data,]; } return response()->json($response, $code); } protected function error($code = 400, $msg = '请求失败', $data = []) { return response()->json([ 'code' => $code, 'msg' => $msg, 'data' => $data, ], $code); } }