From 5df38c1394c00a2efe79c7489ec169d81eff464f Mon Sep 17 00:00:00 2001 From: jochem Date: Fri, 25 May 2018 16:51:22 +0200 Subject: [PATCH] Add support for defining a Spatial reference system for a Point column. See: https://mysqlserverteam.com/spatial-reference-systems-in-mysql-8-0/ See: https://dev.mysql.com/doc/refman/8.0/en/spatial-reference-systems.html --- src/Illuminate/Database/Schema/Blueprint.php | 7 ++++--- .../Database/Schema/Grammars/MySqlGrammar.php | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Database/Schema/Blueprint.php b/src/Illuminate/Database/Schema/Blueprint.php index a61c9b8185b0..cfc461057e3d 100755 --- a/src/Illuminate/Database/Schema/Blueprint.php +++ b/src/Illuminate/Database/Schema/Blueprint.php @@ -1061,12 +1061,13 @@ public function geometry($column) /** * Create a new point column on the table. * - * @param string $column + * @param string $column + * @param null|int $srid * @return \Illuminate\Support\Fluent */ - public function point($column) + public function point($column, $srid = null) { - return $this->addColumn('point', $column); + return $this->addColumn('point', $column, compact('srid')); } /** diff --git a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php index 14576e0e9aad..978882a54d1f 100755 --- a/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php +++ b/src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php @@ -15,7 +15,7 @@ class MySqlGrammar extends Grammar */ protected $modifiers = [ 'Unsigned', 'VirtualAs', 'StoredAs', 'Charset', 'Collate', 'Nullable', - 'Default', 'Increment', 'Comment', 'After', 'First', + 'Default', 'Increment', 'Comment', 'After', 'First', 'Srid', ]; /** @@ -966,6 +966,20 @@ protected function modifyComment(Blueprint $blueprint, Fluent $column) } } + /** + * Get the SQL for a SRID column modifier. + * + * @param \Illuminate\Database\Schema\Blueprint $blueprint + * @param \Illuminate\Support\Fluent $column + * @return string|null + */ + protected function modifySrid(Blueprint $blueprint, Fluent $column) + { + if (! is_null($column->srid) && is_int($column->srid) && $column->srid > 0 ) { + return ' srid '. $column->srid; + } + } + /** * Wrap a single string in keyword identifiers. *