From c042197ced156c84b9a4552d9e2d5c782b441b5e Mon Sep 17 00:00:00 2001 From: MohammadReza Honarkhah Date: Tue, 18 Apr 2017 10:53:07 +0430 Subject: [PATCH] fix bug on geometry mysql 5.7.17 --- src/Mammutgroup/Database/Eloquent/GeometryTrait.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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); + } } }