|
@@ -20,15 +20,22 @@ class AssetController extends Controller
|
|
|
*/
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
- $pageSize=$request->get('page_size') ?? 10;
|
|
|
- $assets = Asset::filter($request->all())
|
|
|
- ->where("parent_id", 0)
|
|
|
+ $fullAsset=[];
|
|
|
+ $paths = Asset::filter($request->all())
|
|
|
->where('company_id',Auth::user()->company_id)
|
|
|
- ->allowed()
|
|
|
- ->with(['children','children.children'])
|
|
|
- ->paginate($pageSize);
|
|
|
+ ->allowed()->pluck('path')->toArray();
|
|
|
+
|
|
|
+ foreach ($paths as $path){
|
|
|
+ $parentAssets = explode(',', substr($path, 1, -1));
|
|
|
+ $fullAsset= array_merge($parentAssets,$fullAsset);
|
|
|
+ }
|
|
|
+
|
|
|
+ $resultAssets = Asset::whereIn('id', $fullAsset)->get()->each(function ($asset) {
|
|
|
+ $asset->requirement_total = $asset->total_requirements_count;
|
|
|
+ $asset->plan_total = $asset->total_plans_count;
|
|
|
+ });
|
|
|
+ return make_tree($resultAssets->toArray());
|
|
|
|
|
|
- return AssetResource::collection($assets);
|
|
|
}
|
|
|
|
|
|
|