|
@@ -20,15 +20,22 @@ class AssetController extends Controller
|
|
|
*/
|
|
|
public function index(Request $request)
|
|
|
{
|
|
|
- $assets = Asset::filter($request->all())
|
|
|
+ $fullAsset=[];
|
|
|
+ $paths = Asset::filter($request->all())
|
|
|
->where('company_id',Auth::user()->company_id)
|
|
|
- ->allowed()->get()->each(function ($asset){
|
|
|
- $asset->requirement_total = $asset->total_requirements_count;
|
|
|
- $asset->plan_total = $asset->total_plans_count;
|
|
|
- });
|
|
|
+ ->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(['id','parent_id','path','code'])->each(function ($asset) {
|
|
|
+ $asset->requirement_total = $asset->total_requirements_count;
|
|
|
+ $asset->plan_total = $asset->total_plans_count;
|
|
|
+ });
|
|
|
+ return make_tree($resultAssets->toArray());
|
|
|
|
|
|
- return make_tree($assets->toArray());
|
|
|
}
|
|
|
|
|
|
/**
|