Browse Source

新增限制条数

duqinya 5 years ago
parent
commit
fc8a0150a0
1 changed files with 4 additions and 0 deletions
  1. 4 0
      app/Repositories/StarNewsRepository.php

+ 4 - 0
app/Repositories/StarNewsRepository.php

@@ -48,6 +48,10 @@ class StarNewsRepository
             'sort' => $request['sort'] ?? 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)) {
             throw new HttpException(500, '添加失败');