From e600eafcef34c3f9c711536caceea2316440bcca Mon Sep 17 00:00:00 2001 From: liapples Date: Thu, 22 Jul 2021 09:53:50 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=85=AC=E5=91=8A=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=88=86=E9=A1=B5=E8=B0=83=E7=94=A8=EF=BC=9B?= =?UTF-8?q?2=E3=80=81=E5=A2=9E=E5=8A=A0show=E6=96=B9=E6=B3=95=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/NoticeController.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/NoticeController.php b/app/Http/Controllers/Api/NoticeController.php index bb7ba11..c96914b 100644 --- a/app/Http/Controllers/Api/NoticeController.php +++ b/app/Http/Controllers/Api/NoticeController.php @@ -11,9 +11,28 @@ use App\Models\Notice; */ class NoticeController extends Controller { + // 公告列表 public function index() { - $list = Notice::limit(10)->get(['title', 'updated_at']); + $page = request()->input('page'); + if ($page && !ctype_digit($page)) { + return $this->error('页码错误'); + } + $list = Notice::where('agent_id', $this->agent_id)->select(['title', 'updated_at'])->simplePaginate(15); return $this->success($list); } + + public function show() + { + $id = request()->input('id'); + if (!$id || !ctype_digit($id)) { + return $this->error('无效的ID'); + } + + $data = Notice::where('agent_id', $this->agent_id)->find($id); + if (!$data) { + return $this->error('公告不存在或已删除'); + } + return $this->success($data); + } }