ソースを参照

新增限制条数

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,
             '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, '添加失败');