From e9d93f6f7e17754e8d64f6f294fa0eba7882b303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=80=E5=B3=B0?= <1feng.0595@gmail.com> Date: Tue, 17 Apr 2018 00:12:04 +0800 Subject: [PATCH] article api --- .../Controllers/Api/ArticleController.php | 36 +++++++++++++++++++ app/Http/Model/Article.php | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ArticleController.php b/app/Http/Controllers/Api/ArticleController.php index 1e4e256..60ecda6 100644 --- a/app/Http/Controllers/Api/ArticleController.php +++ b/app/Http/Controllers/Api/ArticleController.php @@ -61,4 +61,40 @@ class ArticleController extends CommonController return ReturnData::create(ReturnData::SUCCESS,$res); } + //添加 + public function articleAdd(Request $request) + { + if(Helper::isPostRequest()) + { + return $this->getLogic()->add($_POST); + } + } + + //修改 + public function articleUpdate(Request $request) + { + if($request->input('id',null)!=null){$id = $request->input('id');}else{$id='';}if(preg_match('/[0-9]*/',$id)){}else{return ReturnData::create(ReturnData::PARAMS_ERROR);} + + if(Helper::isPostRequest()) + { + unset($_POST['id']); + $where['id'] = $id; + + return $this->getLogic()->edit($_POST,$where); + } + } + + //删除 + public function articleDelete(Request $request) + { + if($request->input('id',null)!=null){$id = $request->input('id');}else{$id='';}if(preg_match('/[0-9]*/',$id)){}else{return ReturnData::create(ReturnData::PARAMS_ERROR);} + + if(Helper::isPostRequest()) + { + unset($_POST['id']); + $where['id'] = $id; + + return $this->getLogic()->del($where); + } + } } \ No newline at end of file diff --git a/app/Http/Model/Article.php b/app/Http/Model/Article.php index cb8916c..73ad279 100644 --- a/app/Http/Model/Article.php +++ b/app/Http/Model/Article.php @@ -184,7 +184,7 @@ class Article extends BaseModel if($where){$res = $res->where($where);} if($field){if(is_array($field)){$res = $res->select($field);}else{$res = $res->select(\DB::raw($field));}} - $res = $res->find(); + $res = $res->first(); return $res; }