From 5d7b5eb8f66da7c2bde4024dda35a4304dbd73b9 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 2 Jan 2020 00:43:25 +0800 Subject: [PATCH] update --- .../Controllers/Admin/CouponController.php | 14 +++++++---- .../Controllers/Admin/NoticeController.php | 24 +++++++------------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/Admin/CouponController.php b/app/Http/Controllers/Admin/CouponController.php index 93cb2f85..0cd063eb 100644 --- a/app/Http/Controllers/Admin/CouponController.php +++ b/app/Http/Controllers/Admin/CouponController.php @@ -26,10 +26,16 @@ class CouponController extends Controller 'limit_use' ]); - $params['code'] = Helper::randomChar(8); - if (!Coupon::create($params)) { - abort(500, '创建失败'); - } + if (!$request->input('id')) { + $params['code'] = Helper::randomChar(8); + if (!Coupon::create($params)) { + abort(500, '创建失败'); + } + } else { + if (!Coupon::find($request->input('id'))->update($params)) { + abort(500, '保存失败'); + } + } return response([ 'data' => true diff --git a/app/Http/Controllers/Admin/NoticeController.php b/app/Http/Controllers/Admin/NoticeController.php index c5572774..5162e109 100644 --- a/app/Http/Controllers/Admin/NoticeController.php +++ b/app/Http/Controllers/Admin/NoticeController.php @@ -22,22 +22,14 @@ class NoticeController extends Controller 'content', 'img_url' ]); - if (!Notice::create($data)) { - abort(500, '保存失败'); - } - return response([ - 'data' => true - ]); - } - - public function update (NoticeSave $request) { - $data = $request->only([ - 'title', - 'content', - 'img_url' - ]); - if (!Notice::where('id', $request->input('id'))->update($data)) { - abort(500, '保存失败'); + if (!$request->input('id')) { + if (!Notice::create($data)) { + abort(500, '保存失败'); + } + } else { + if (!Notice::find($request->input('id'))->update($data)) { + abort(500, '保存失败'); + } } return response([ 'data' => true