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

Commit 97c294f

Browse files
authored
Merge pull request #180 from RomainMazB/patch-1
Support upsert Fix #149
2 parents 1c96de3 + 801b129 commit 97c294f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/Eloquent/Builder.php

+18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,24 @@ public function update(array $values)
2121
return parent::update($values);
2222
}
2323

24+
public function upsert(array $values, $uniqueBy, $update = null)
25+
{
26+
foreach ($values as &$row) {
27+
foreach ($row as $column => &$value) {
28+
if ($value instanceof GeometryInterface) {
29+
if (is_null($this->model)) {
30+
$value = $this->asWKT($value);
31+
} else {
32+
$attrs = $this->model->getPostgisType($column);
33+
$value = $this->model->asWKT($value, $attrs);
34+
}
35+
}
36+
}
37+
}
38+
39+
return parent::upsert($values, $uniqueBy, $update);
40+
}
41+
2442
protected function asWKT(GeometryInterface $geometry)
2543
{
2644
return $this->getQuery()->raw(sprintf("%s.ST_GeogFromText('%s')",

0 commit comments

Comments
 (0)