diff --git a/app/Http/Controllers/OrganizationController.php b/app/Http/Controllers/OrganizationController.php index 4822745..79b2697 100644 --- a/app/Http/Controllers/OrganizationController.php +++ b/app/Http/Controllers/OrganizationController.php @@ -1,5 +1,7 @@ withoutEagerLoads(['city']) - ->select(['id', 'name', 'county_id']) + ->select([ + 'id', + 'name', + 'county_id', + 'type', + 'status', + 'area', + 'created_at', + 'updated_at', + ]) ->with([ 'riskCategories', 'activityCounties', 'expertises', 'resourceTypes', + 'county', ]) - ->with('volunteers') + ->withCount('volunteers') ->get() ); } diff --git a/app/Http/Controllers/ResourceController.php b/app/Http/Controllers/ResourceController.php index 2cb9f63..e236558 100644 --- a/app/Http/Controllers/ResourceController.php +++ b/app/Http/Controllers/ResourceController.php @@ -1,5 +1,7 @@ with('county') - ->with('organisation') - ->with('category') - ->with('subcategory') - ->with('types') + ->with([ + 'county', + 'category', + 'subcategory', + 'types', + 'organisation' => fn ($query) => $query + ->withoutEagerLoads() + ->select('id', 'name'), + ]) ->get() ); } - } diff --git a/app/Http/Resources/OrganizationResource.php b/app/Http/Resources/OrganizationResource.php index 3bab5ea..f08a47f 100644 --- a/app/Http/Resources/OrganizationResource.php +++ b/app/Http/Resources/OrganizationResource.php @@ -1,5 +1,7 @@ $this->id, + return [ + 'id' => $this->id, 'name' => $this->name, 'type' => $this->type, 'status' => $this->status, - 'expertises_area' => IdAndNameResource::collection($this->expertises), - 'risc_category' => IdAndNameResource::collection($this->riskCategories), - 'action_type' => IdAndNameResource::collection($this->resourceTypes), - 'activity_area' => $this->area, - 'county' => IdAndNameResource::collection($this->activityCounties), - 'created_at' => $this->created_at->format("Y-m-d H:i:s"), - 'updated_at' => $this->updated_at->format("Y-m-d H:i:s"), - 'volunteers_count' => $this->volunteers->count(), + 'expertises' => IdAndNameResource::collection($this->expertises), + 'risk_categories' => IdAndNameResource::collection($this->riskCategories), + 'resource_types' => IdAndNameResource::collection($this->resourceTypes), + 'area' => $this->area, + 'county' => $this->county->name, + 'activity_counties' => IdAndNameResource::collection($this->activityCounties), + 'created_at' => $this->created_at->format('Y-m-d H:i:s'), + 'updated_at' => $this->updated_at->format('Y-m-d H:i:s'), + 'volunteers_count' => $this->volunteers_count, ]; } } diff --git a/app/Http/Resources/ResourceResource.php b/app/Http/Resources/ResourceResource.php index 3975f7e..f5ed9ed 100644 --- a/app/Http/Resources/ResourceResource.php +++ b/app/Http/Resources/ResourceResource.php @@ -1,5 +1,7 @@ $this->id, + return [ + 'id' => $this->id, 'name' => $this->name, - 'county' => IdAndNameResource::make($this->county), + 'county' => $this->county->name, 'organization' => IdAndNameResource::make($this->organisation), 'category' => IdAndNameResource::make($this->category), 'subcategory' => IdAndNameResource::make($this->subcategory), -// 'types' => IdAndNameResource::collection($this->types), - 'created_at' => $this->created_at->format("Y-m-d H:i:s"), - 'updated_at' => $this->updated_at->format("Y-m-d H:i:s"), + 'types' => IdAndNameResource::collection($this->types), + 'created_at' => $this->created_at->format('Y-m-d H:i:s'), + 'updated_at' => $this->updated_at->format('Y-m-d H:i:s'), ]; - } }