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

Commit

Permalink
Support upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainMazB authored Dec 6, 2022
1 parent 2483bd8 commit 801b129
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 801b129

Please sign in to comment.