Prechádzať zdrojové kódy

评论列表判断内容

wzq 5 rokov pred
rodič
commit
b9dadf3743

+ 4 - 0
app/Http/Controllers/V1/PostController.php

@@ -270,6 +270,10 @@ class PostController extends Controller
         if ($validator->fails()) {
             return jsonError($validator->errors()->first());
         }
+        $exists = $this->postRepositories->detailExists($request['post_id']);
+        if (!$exists) {
+            return jsonError('获取内容信息失败');
+        }
         $list = $this->postRepositories->commentList($request->all());
         $fractal = new Manager();
         $resource = new Collection($list, new CommentTransformer());

+ 8 - 0
app/Repositories/PostRepositories.php

@@ -362,6 +362,14 @@ class PostRepositories
             ->find($id);
     }
 
+    /**
+     * 内容是否存在
+     */
+    public function detailExists($id)
+    {
+        return $this->post->where('id', $id)->exists();
+    }
+
     /**
      * 推荐内容列表
      */