Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
fix support on builder update
Browse files Browse the repository at this point in the history
  • Loading branch information
luizguilhermefr committed Jul 4, 2018
1 parent a1c5e47 commit 6261e1c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
23 changes: 9 additions & 14 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,21 @@ public function update(array $values)
{
foreach ($values as $key => &$value) {
if ($value instanceof GeometryInterface) {
$attrs = $this->getPostgisType($key);
$value = $this->asWKT($value, $attrs);
if (is_null($this->model)) {
$value = $this->asWKT($value);
} else {
$attrs = $this->model->getPostgisType($key);
$value = $this->model->asWKT($value, $attrs);
}
}
}

return parent::update($values);
}

protected function getPostgisFields()
protected function asWKT(GeometryInterface $geometry)
{
return $this->getModel()->getPostgisFields();
}

protected function getPostgisType($key)
{
return $this->getModel()->getPostgisType($key);
}

protected function asWKT(GeometryInterface $geometry, $attrs)
{
return $this->getModel()->asWKT($geometry, $attrs);
return $this->getQuery()->raw(sprintf("%s.ST_GeogFromText('%s')",
function_exists('config') ? config('postgis.schema') : 'public', $geometry->toWKT()));
}
}
2 changes: 1 addition & 1 deletion src/Eloquent/PostgisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function geomFromText(GeometryInterface $geometry, $srid = 4326)
function_exists('config') ? config('postgis.schema') : 'public', $geometry->toWKT(), $srid));
}

protected function asWKT(GeometryInterface $geometry, $attrs)
public function asWKT(GeometryInterface $geometry, $attrs)
{
switch (strtoupper($attrs['geomtype'])) {
case 'GEOMETRY':
Expand Down

0 comments on commit 6261e1c

Please sign in to comment.