From 0fb8c867358184be834a63452b471f09577bddb0 Mon Sep 17 00:00:00 2001 From: sayadaazami Date: Sat, 15 Jul 2017 11:28:26 +0430 Subject: [PATCH] bugfix multiple column seprated with , on select query --- .../Database/Eloquent/GeometryTrait.php | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/Mammutgroup/Database/Eloquent/GeometryTrait.php b/src/Mammutgroup/Database/Eloquent/GeometryTrait.php index 07aa004..137582c 100755 --- a/src/Mammutgroup/Database/Eloquent/GeometryTrait.php +++ b/src/Mammutgroup/Database/Eloquent/GeometryTrait.php @@ -23,27 +23,32 @@ public function newEloquentBuilder($query) public function newQuery($excludeDeleted = true) { - $raw = ''; - foreach ($this->geoFields as $column) { - $raw .= ' ST_AsBinary(' . $column . ') as ' . $column . '_alias '; + if (empty($this->geoFields)) { + return parent::newQuery($excludeDeleted); } - return parent::newQuery($excludeDeleted)->addSelect('*', \DB::raw($raw)); + $raw = []; + foreach ($this->geoFields as $column) { + $raw[] = 'ST_AsBinary(' . $column . ') as ' . $column . '_alias '; + } + + return parent::newQuery($excludeDeleted)->addSelect('*', \DB::raw(implode(', ', $raw))); } public function setRawAttributes(array $attributes, $sync = false) { - $pgfields = $this->getGeoFields(); - - foreach ($attributes as $attribute => &$value) { + if (!empty($this->geoFields)) { + $pgfields = $this->getGeoFields(); + foreach ($attributes as $attribute => &$value) { - if (in_array($attribute, $pgfields)) { - $value = $attributes[$attribute.'_alias']; + if (in_array($attribute, $pgfields)) { + $value = $attributes[$attribute . '_alias']; - if(is_string($value) && strlen($value) >= 15){ + if (is_string($value) && strlen($value) >= 15) { - $value = Geometry::fromWKB($value); - } + $value = Geometry::fromWKB($value); + } + } } }