Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 0a8aa31

Browse files
author
thaisonle
committed
Fixed PostgisTrait to handle GeometryCollection correctly
The geometrycollection migration method inserts the column as a geometry column instead of a geography column. This causes saves to fail since the insert is trying to save a geography instead of a geometry. The GeometryCollection class does extend the Geometry class which implements the GeometryInterface that is checked in the if statement to skip model attributes that are not geometries.
1 parent 84a6d3f commit 0a8aa31

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Eloquent/PostgisTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ public function newEloquentBuilder($query)
2424
protected function performInsert(EloquentBuilder $query, array $options = [])
2525
{
2626
foreach ($this->attributes as $key => &$value) {
27-
if ($value instanceof GeometryInterface) {
27+
if ($value instanceof GeometryInterface && ! $value instanceof GeometryCollection) {
2828
$this->geometries[$key] = $value; //Preserve the geometry objects prior to the insert
2929
$value = $this->getConnection()->raw(sprintf("ST_GeogFromText('%s')", $value->toWKT()));
30+
} else if ($value instanceof GeometryInterface && $value instanceof GeometryCollection) {
31+
$this->geometries[$key] = $value; //Preserve the geometry objects prior to the insert
32+
$value = $this->getConnection()->raw(sprintf("ST_GeomFromText('%s', 4326)", $value->toWKT()));
3033
}
3134
}
3235

0 commit comments

Comments
 (0)