From a30920233bce072d5f98a394d015ac6507b6a532 Mon Sep 17 00:00:00 2001 From: JORGE Date: Thu, 18 Apr 2024 11:21:19 -0400 Subject: [PATCH] add relation with polygon for site polygon --- .../V2/Terrafund/TerrafundCreateGeometryController.php | 5 +---- app/Models/V2/Sites/SitePolygon.php | 8 +++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index e8738bba3..61eb81861 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -489,10 +489,7 @@ public function checkWithinCountry(Request $request) return response()->json(['error' => 'Site polygon data not found for the specified polygonUuid'], 404); } - // Find the country ISO using project_id from v2projects - $countryIso = Project::where('uuid', $sitePolygonData->project_id) - ->value('country'); - + $countryIso = $sitePolygonData->project->country; if (! $countryIso) { return response()->json(['error' => 'Country ISO not found for the specified project_id'], 404); } diff --git a/app/Models/V2/Sites/SitePolygon.php b/app/Models/V2/Sites/SitePolygon.php index 3143d7d23..bfd244dca 100644 --- a/app/Models/V2/Sites/SitePolygon.php +++ b/app/Models/V2/Sites/SitePolygon.php @@ -4,6 +4,7 @@ use App\Models\Traits\HasUuid; use App\Models\V2\PolygonGeometry; +use App\Models\V2\Projects\Project; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -21,6 +22,7 @@ class SitePolygon extends Model 'poly_name', 'site_id', 'site_name', + 'project_id', 'poly_label', 'plantstart', 'plantend', @@ -34,6 +36,10 @@ class SitePolygon extends Model public function polygonGeometry() { - return $this->belongsTo(PolygonGeometry::class, 'poly_id', 'id'); + return $this->belongsTo(PolygonGeometry::class, 'poly_id', 'uuid'); + } + public function project() + { + return $this->belongsTo(Project::class, 'project_id','uuid'); } }