浏览代码

Update CollectionController

Daniel Supernault 6 年之前
父节点
当前提交
6791d13fc5
共有 1 个文件被更改,包括 31 次插入0 次删除
  1. 31 0
      app/Http/Controllers/CollectionController.php

+ 31 - 0
app/Http/Controllers/CollectionController.php

@@ -167,4 +167,35 @@ class CollectionController extends Controller
 
         return response()->json($res);
     }
+
+    public function getUserCollections(Request $request, int $id)
+    {
+        $profile = Profile::whereNull('status')
+            ->whereNull('domain')
+            ->findOrFail($id);
+
+        if($profile->is_private) {
+            abort_if(!Auth::check(), 404);
+            abort_if(!$profile->followedBy(Auth::user()->profile) && $profile->id != Auth::user()->profile_id, 404);
+        }
+
+        return $profile
+            ->collections()
+            ->has('posts')
+            ->with('posts')
+            ->whereVisibility('public')
+            ->whereNotNull('published_at')
+            ->orderByDesc('published_at')
+            ->paginate(9)
+            ->map(function($collection) {
+                return [
+                    'id' => $collection->id,
+                    'title' => $collection->title,
+                    'description' => $collection->description,
+                    'thumb' => $collection->posts()->first()->thumb(),
+                    'url' => $collection->url(),
+                    'published_at' => $collection->published_at
+                ];
+        });
+    }
 }