peterguo 2 mesi fa
parent
commit
a9e89a1337

+ 9 - 3
app/Http/Controllers/API/ContainerController.php

@@ -220,9 +220,15 @@ class ContainerController extends Controller
 
     public function linkage(string $libraryId)
     {
-        $items = Container::select(['id', 'name'])->withCount(['folder' => function ($query) {
-            $query->where('parent_id', 0);
-        }])->allowed()->where("library_id", $libraryId)->get()->each(function ($items) {
+        $items = Container::select(['id', 'name'])
+            ->withCount(['folder' => function ($query) {
+                $query->where('parent_id', 0);
+            }])
+            ->withCount(['file' => function ($query) {
+                $query->where('folder_id', 0);
+            }])
+            ->allowed()->where("library_id", $libraryId)->get()->each(function ($items) {
+
             // 设置固定的type值
             $items->type = 'container';
             $items->uniId=$items->type.'_'.$items->id;

+ 5 - 0
app/Models/Container.php

@@ -68,4 +68,9 @@ class Container extends Model
     {
         return $this->hasMany(Folder::class, "object_id")->where("object_type", ActionObjectType::CONTAINER->value);
     }
+
+    public function file()
+    {
+        return $this->hasMany(File::class, "object_id")->where("object_type", ActionObjectType::CONTAINER->value);
+    }
 }