Browse Source

library_count

peterguo 1 tháng trước cách đây
mục cha
commit
8faafe61cc
1 tập tin đã thay đổi với 11 bổ sung10 xóa
  1. 11 10
      app/Http/Controllers/API/AssetController.php

+ 11 - 10
app/Http/Controllers/API/AssetController.php

@@ -175,16 +175,17 @@ class AssetController extends Controller
     public function tree()
     {
         $attachmentArray = [];
-        $assets = Asset::allowed()->get(['id', 'name', 'parent_id'])->each(function ($assets)use (&$attachmentArray){
-            $attachmentArray[]=[
-            'parent_id'=>$assets->id,
-            'type'=>'attachment',
-            'name'=>'attachment',
-            'uuId'=>'attachment_'.$assets->id,
-            'id'=>'asset_id_'.$assets->id,
-        ];
-            $assets->type='asset';
-            $assets->uniId=$assets->type.'_'.$assets->id;
+        $assets = Asset::withCount('library')->allowed()->get(['id', 'name', 'parent_id'])
+            ->each(function ($assets) use (&$attachmentArray) {
+                $attachmentArray[]=[
+                    'parent_id'=>$assets->id,
+                    'type'=>'attachment',
+                    'name'=>'attachment',
+                    'uuId'=>'attachment_'.$assets->id,
+                    'id'=>'asset_id_'.$assets->id,
+                ];
+                $assets->type='asset';
+                $assets->uniId=$assets->type.'_'.$assets->id;
         });
 
         return $this->success([