diff --git a/src/Eloquent/Builder.php b/src/Eloquent/Builder.php index 3c6f1b1..3f74ffe 100644 --- a/src/Eloquent/Builder.php +++ b/src/Eloquent/Builder.php @@ -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')",