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

Commit 1412576

Browse files
authored
Merge pull request #97 from grimzy/master
Use the schema defined in the Laravel configuration
2 parents b751206 + e2c786d commit 1412576

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

config/postgis.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
return [
4+
5+
'schema' => 'public' // Schema for the Postgis extension
6+
7+
];

src/DatabaseServiceProvider.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
*/
1111
class DatabaseServiceProvider extends PostgresDatabaseServiceProvider
1212
{
13+
public function boot() {
14+
// Load the config
15+
$config_path = __DIR__ . '/../config/postgis.php';
16+
$this->publishes([$config_path => config_path('postgis.php')], 'postgis');
17+
$this->mergeConfigFrom($config_path, 'postgis');
18+
}
19+
1320
/**
1421
* Register the service provider.
1522
*

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('postgis.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('postgis.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('postgis.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('postgis.schema'), $value->toWKT())
53+
);
4554
}
4655
}
4756
}

0 commit comments

Comments
 (0)