Просмотр исходного кода

使用 ArticleCollection 获取目录

visuddhinanda 5 дней назад
Родитель
Сommit
dde3643a4d
1 измененных файлов с 9 добавлено и 11 удалено
  1. 9 11
      api-v12/app/Http/Resources/CollectionResource.php

+ 9 - 11
api-v12/app/Http/Resources/CollectionResource.php

@@ -24,25 +24,23 @@ class CollectionResource extends JsonResource
             "subtitle" => $this->subtitle,
             "summary" => $this->summary,
             "studio" => StudioApi::getById($this->owner),
-            "childrenNumber" => ArticleCollection::where('collect_id',$this->uid)->count(),
+            "childrenNumber" => ArticleCollection::where('collect_id', $this->uid)->count(),
             "status" => $this->status,
             'lang' => $this->lang,
             "created_at" => $this->created_at,
             "updated_at" => $this->updated_at,
         ];
         $channel = ChannelApi::getById($this->default_channel);
-        if($channel){
+        if ($channel) {
             $data['default_channel'] = $channel;
         }
-        if($this->fullArticleList===true){
-            $data["article_list"] = \json_decode($this->article_list);
-        }else{
-            if(isset($this->article_list) && !empty($this->article_list) ){
-                $arrList = \json_decode($this->article_list);
-                if(is_array($arrList)){
-                    $data["article_list"] = array_slice($arrList,0,4);
-                }
-            }
+        $arrList = ArticleCollection::where('collect_id', $this->uid)
+            ->select(['article_id', 'level', 'title'])
+            ->orderBy('id')->get()->toArray();
+        if ($this->fullArticleList === true) {
+            $data["article_list"] = $arrList;
+        } else {
+            $data["article_list"] = array_slice($arrList, 0, 4);
         }
 
         return $data;