Skip to content

Commit

Permalink
fix bug on geometry mysql 5.7.17
Browse files Browse the repository at this point in the history
  • Loading branch information
honarkhah committed Apr 18, 2017
1 parent 373cdd6 commit c042197
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Mammutgroup/Database/Eloquent/GeometryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit c042197

Please sign in to comment.