Skip to content

Commit 3f7ee80

Browse files
raymondtritaylorotwell
authored andcommitted
[6.x] Added support for separation between geometry and geography types (#30545)
* Added support for separation between geometry and geography types when using postgres with postgis-created types * StyleCI fix * StyleCI fix * Refactored to use nested conditionals with an early return * Refactored to be non-breaking and use the isGeometry fluent property, and cleaned logic * StyleCI * Update PostgresGrammar.php
1 parent 1c354c2 commit 3f7ee80

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ protected function typeMacAddress(Fluent $column)
788788
*/
789789
protected function typeGeometry(Fluent $column)
790790
{
791-
return $this->formatPostGisType('geometry');
791+
return $this->formatPostGisType('geometry', $column);
792792
}
793793

794794
/**
@@ -799,7 +799,7 @@ protected function typeGeometry(Fluent $column)
799799
*/
800800
protected function typePoint(Fluent $column)
801801
{
802-
return $this->formatPostGisType('point');
802+
return $this->formatPostGisType('point', $column);
803803
}
804804

805805
/**
@@ -810,7 +810,7 @@ protected function typePoint(Fluent $column)
810810
*/
811811
protected function typeLineString(Fluent $column)
812812
{
813-
return $this->formatPostGisType('linestring');
813+
return $this->formatPostGisType('linestring', $column);
814814
}
815815

816816
/**
@@ -821,7 +821,7 @@ protected function typeLineString(Fluent $column)
821821
*/
822822
protected function typePolygon(Fluent $column)
823823
{
824-
return $this->formatPostGisType('polygon');
824+
return $this->formatPostGisType('polygon', $column);
825825
}
826826

827827
/**
@@ -832,7 +832,7 @@ protected function typePolygon(Fluent $column)
832832
*/
833833
protected function typeGeometryCollection(Fluent $column)
834834
{
835-
return $this->formatPostGisType('geometrycollection');
835+
return $this->formatPostGisType('geometrycollection', $column);
836836
}
837837

838838
/**
@@ -843,7 +843,7 @@ protected function typeGeometryCollection(Fluent $column)
843843
*/
844844
protected function typeMultiPoint(Fluent $column)
845845
{
846-
return $this->formatPostGisType('multipoint');
846+
return $this->formatPostGisType('multipoint', $column);
847847
}
848848

849849
/**
@@ -854,7 +854,7 @@ protected function typeMultiPoint(Fluent $column)
854854
*/
855855
public function typeMultiLineString(Fluent $column)
856856
{
857-
return $this->formatPostGisType('multilinestring');
857+
return $this->formatPostGisType('multilinestring', $column);
858858
}
859859

860860
/**
@@ -865,7 +865,7 @@ public function typeMultiLineString(Fluent $column)
865865
*/
866866
protected function typeMultiPolygon(Fluent $column)
867867
{
868-
return $this->formatPostGisType('multipolygon');
868+
return $this->formatPostGisType('multipolygon', $column);
869869
}
870870

871871
/**
@@ -876,18 +876,23 @@ protected function typeMultiPolygon(Fluent $column)
876876
*/
877877
protected function typeMultiPolygonZ(Fluent $column)
878878
{
879-
return $this->formatPostGisType('multipolygonz');
879+
return $this->formatPostGisType('multipolygonz', $column);
880880
}
881881

882882
/**
883883
* Format the column definition for a PostGIS spatial type.
884884
*
885885
* @param string $type
886+
* @param \Illuminate\Support\Fluent $column
886887
* @return string
887888
*/
888-
private function formatPostGisType(string $type)
889+
private function formatPostGisType(string $type, Fluent $column)
889890
{
890-
return "geography($type, 4326)";
891+
if ($column->isGeometry !== null) {
892+
return "geometry($type".($column->projection === null ? '' : ", $column->projection").')';
893+
}
894+
895+
return "geography($type, ".($column->projection ?? '4326').')';
891896
}
892897

893898
/**

0 commit comments

Comments
 (0)