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

Commit

Permalink
Merge pull request #180 from RomainMazB/patch-1
Browse files Browse the repository at this point in the history
Support upsert Fix #149
  • Loading branch information
mstaack authored Mar 27, 2023
2 parents 1c96de3 + 801b129 commit 97c294f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ public function update(array $values)
return parent::update($values);
}

public function upsert(array $values, $uniqueBy, $update = null)
{
foreach ($values as &$row) {
foreach ($row as $column => &$value) {
if ($value instanceof GeometryInterface) {
if (is_null($this->model)) {
$value = $this->asWKT($value);
} else {
$attrs = $this->model->getPostgisType($column);
$value = $this->model->asWKT($value, $attrs);
}
}
}
}

return parent::upsert($values, $uniqueBy, $update);
}

protected function asWKT(GeometryInterface $geometry)
{
return $this->getQuery()->raw(sprintf("%s.ST_GeogFromText('%s')",
Expand Down

0 comments on commit 97c294f

Please sign in to comment.