Skip to content

Commit 7dff1f3

Browse files
committed
Use the schema defined in the Laravel configuration (database.connections.pgsql.schema)
1 parent b751206 commit 7dff1f3

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Eloquent/Builder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ protected function getPostgisFields()
2424

2525
protected function asWKT(GeometryInterface $geometry)
2626
{
27-
return $this->getQuery()->raw(sprintf("public.ST_GeogFromText('%s')", $geometry->toWKT()));
27+
return $this->getQuery()->raw(
28+
sprintf("%s.ST_GeogFromText('%s')", config('database.connections.pgsql.schema'), $geometry->toWKT())
29+
);
30+
2831
}
2932
}

src/Eloquent/PostgisTrait.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,24 @@ protected function performInsert(EloquentBuilder $query, array $options = [])
3333
$attrs = $this->getPostgisType($key);
3434
switch (strtoupper($attrs['geomtype'])) {
3535
case 'GEOMETRY':
36-
$this->attributes[$key] = $this->getConnection()->raw(sprintf("public.ST_GeomFromText('%s', '%d')", $value->toWKT(), $attrs['srid']));
36+
$this->attributes[$key] = $this->getConnection()->raw(
37+
sprintf("%s.ST_GeomFromText('%s', '%d')",
38+
config('database.connections.pgsql.schema'), $value->toWKT(), $attrs['srid'])
39+
);
3740
break;
3841
case 'GEOGRAPHY':
3942
default:
40-
$this->attributes[$key] = $this->getConnection()->raw(sprintf("public.ST_GeogFromText('%s')", $value->toWKT()));
43+
$this->attributes[$key] = $this->getConnection()->raw(
44+
sprintf("%s.ST_GeogFromText('%s')",
45+
config('database.connections.pgsql.schema'), $value->toWKT())
46+
);
4147
break;
4248
}
4349
} else {
44-
$this->attributes[$key] = $this->getConnection()->raw(sprintf("public.ST_GeomFromText('%s', 4326)", $value->toWKT()));
50+
$this->attributes[$key] = $this->getConnection()->raw(
51+
sprintf("%s.ST_GeomFromText('%s', 4326)",
52+
config('database.connections.pgsql.schema'), $value->toWKT())
53+
);
4554
}
4655
}
4756
}

0 commit comments

Comments
 (0)