Skip to content

Commit

Permalink
bugfix multiple column seprated with , on select query
Browse files Browse the repository at this point in the history
  • Loading branch information
sayadaazami authored Jul 15, 2017
1 parent 68af2fa commit 0fb8c86
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/Mammutgroup/Database/Eloquent/GeometryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

Expand Down

0 comments on commit 0fb8c86

Please sign in to comment.