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

Support upsert Fix #149 #180

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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