Skip to content

Commit

Permalink
add relation with polygon for site polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
egrojMonroy committed Apr 18, 2024
1 parent cc4103f commit a309202
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 7 additions & 1 deletion app/Models/V2/Sites/SitePolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -21,6 +22,7 @@ class SitePolygon extends Model
'poly_name',
'site_id',
'site_name',
'project_id',
'poly_label',
'plantstart',
'plantend',
Expand All @@ -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');
}
}

0 comments on commit a309202

Please sign in to comment.