瀏覽代碼

新增限制条数

duqinya 5 年之前
父節點
當前提交
fc8a0150a0
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      app/Repositories/StarNewsRepository.php

+ 4 - 0
app/Repositories/StarNewsRepository.php

@@ -48,6 +48,10 @@ class StarNewsRepository
             'sort' => $request['sort'] ?? 0,
             'sort' => $request['sort'] ?? 0,
             'status' => $request['status'] ?? 0,
             'status' => $request['status'] ?? 0,
         ];
         ];
+        $open_news = $this->starNews->where('status',1)->count();
+        if ($open_news >= 5 && $request['status'] == 1){
+            throw new HttpException(500, '最多开启5条新闻');
+        }
 
 
         if (!$this->starNews->create($data)) {
         if (!$this->starNews->create($data)) {
             throw new HttpException(500, '添加失败');
             throw new HttpException(500, '添加失败');