diff --git a/src/Mammutgroup/Database/Eloquent/GeometryTrait.php b/src/Mammutgroup/Database/Eloquent/GeometryTrait.php index 66cc5cb..07aa004 100644 --- a/src/Mammutgroup/Database/Eloquent/GeometryTrait.php +++ b/src/Mammutgroup/Database/Eloquent/GeometryTrait.php @@ -25,7 +25,7 @@ public function newQuery($excludeDeleted = true) { $raw = ''; foreach ($this->geoFields as $column) { - $raw .= ' ST_AsBinary(' . $column . ') as ' . $column . ' '; + $raw .= ' ST_AsBinary(' . $column . ') as ' . $column . '_alias '; } return parent::newQuery($excludeDeleted)->addSelect('*', \DB::raw($raw)); @@ -36,9 +36,14 @@ public function setRawAttributes(array $attributes, $sync = false) $pgfields = $this->getGeoFields(); foreach ($attributes as $attribute => &$value) { - if (in_array($attribute, $pgfields) && is_string($value) && strlen($value) >= 15) { - $value = Geometry::fromWKB($value); + if (in_array($attribute, $pgfields)) { + $value = $attributes[$attribute.'_alias']; + + if(is_string($value) && strlen($value) >= 15){ + + $value = Geometry::fromWKB($value); + } } }