whitelist??''); $whitelistName=User::query()->whereIn('id',$whitelist)->get(); $approvalCounts = Approval::query() ->allowed(true) ->selectRaw('sum(case when status = \'doing\' then 1 else 0 end) as approval_doing_count, sum(case when status = \'canceled\' then 1 else 0 end) as approval_canceled_count, sum(case when status = \'rejected\' then 1 else 0 end) as approval_rejected_count') ->first(); return[ 'requirement_total' => Requirement::query()->whereIn('asset_id',$this->child_id)->count(), 'plan_total' => $this->plans()->count(), 'project_total' => $this->projects()->count(), 'plan_unexpired_total' => $planTotalCount = $this->plans()->where('end', '>=', $now) ->get() ->count(), 'project_unexpired_total' => $planTotalCount = $this->projects()->where('end', '>=', $now) ->get() ->count(), 'asset_total'=>Asset::query()->allowed()->count(), 'asset_closed_total'=>Asset::query()->allowed()->where('status','closed')->count(), 'id' => $this->id, 'name' => $this->name, 'code' => $this->code, 'description' => $this->description?(new \App\Services\File\ImageUrlService)->getImageUrl($this->description):null, 'status' => $this->status, 'created_by' =>new UserProfileResource($this->createdBy), 'owner' => new UserProfileResource($this->byOwner), 'address' => $this->address, 'group_id' => new AssetGroupResource($this->assetGroup), 'geo_address_code' => $this->geo_address_code, 'acl' => $this->acl, 'latitude' => $this->latitude, 'longitude' => $this->longitude, 'whitelist'=>$whitelist, 'whitelist_name' => UserProfileResource::collection($whitelistName), 'parent_asset' => new AssetResource($this->parent), 'created_at' => (string)$this->created_at, 'equity_interest'=>$this->equity_interest, 'developer' =>$this->developer, 'date_completed' =>$this->date_completed, 'total_floor_area' => $this->total_floor_area, 'contact_person'=>$this->contact_person, 'contact_phone'=>$this->contact_phone, 'contact_email'=>$this->contact_email, 'property'=> $this->property, 'building_type_description'=>$this->building_type_description, 'children' => $this->when($this->children->isNotEmpty(), function () { return $this->children->map(function ($child) { return new AssetResource($child, $this->level); })->all(); }), 'area_unit'=>$this->area_unit, 'approval_doing_count' => $approvalCounts->approval_doing_count, 'approval_canceled_count' => $approvalCounts->approval_canceled_count, 'approval_rejected_count' => $approvalCounts->approval_rejected_count, ]; } }