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

Commit c0873d8

Browse files
committed
Merge pull request #26 from thaisonle/patch-1
Fixed PostgisTrait to handle GeometryCollection correctly
2 parents 84a6d3f + 0a8aa31 commit c0873d8

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)