Skip to content

Commit e050c91

Browse files
Output new Laravel 11 geo column types (#717)
1 parent 3df7f03 commit e050c91

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

src/Generators/MigrationGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ protected function buildDefinition(Model $model): string
152152
if (!empty($columnAttributes) && !$this->isIdColumnType($column->dataType())) {
153153
$column_definition .= ', ';
154154

155+
if (in_array($column->dataType(), ['geography', 'geometry'])) {
156+
$columnAttributes[0] = Str::wrap($columnAttributes[0], "'");
157+
}
158+
155159
if (in_array($column->dataType(), ['set', 'enum'])) {
156160
$column_definition .= json_encode($columnAttributes);
157161
} else {

src/Lexers/ModelLexer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ModelLexer implements Lexer
3636
'enum' => 'enum',
3737
'float' => 'float',
3838
'fulltext' => 'fullText',
39+
'geography' => 'geography',
3940
'geometry' => 'geometry',
4041
'geometrycollection' => 'geometryCollection',
4142
'increments' => 'increments',

tests/Feature/Generators/MigrationGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ public static function modelTreeDataProvider()
646646
['drafts/foreign-key-on-delete.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/foreign-key-on-delete.php'],
647647
['drafts/nullable-columns-with-foreign.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/nullable-columns-with-foreign.php'],
648648
['drafts/omits-length-for-integers.yaml', 'database/migrations/timestamp_create_omits_table.php', 'migrations/omits-length-for-integers.php'],
649+
['drafts/geometry-columns.yaml', 'database/migrations/timestamp_create_locations_table.php', 'migrations/geometry-columns.php'],
649650
];
650651
}
651652
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
models:
2+
Location:
3+
name: string:100
4+
description: text nullable
5+
coordinates: geography:point,4326
6+
positions: geometry:point,0
7+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('locations', function (Blueprint $table) {
15+
$table->id();
16+
$table->string('name', 100);
17+
$table->text('description')->nullable();
18+
$table->geography('coordinates', 'point', 4326);
19+
$table->geometry('positions', 'point', 0);
20+
$table->timestamps();
21+
});
22+
}
23+
24+
/**
25+
* Reverse the migrations.
26+
*/
27+
public function down(): void
28+
{
29+
Schema::dropIfExists('locations');
30+
}
31+
};

0 commit comments

Comments
 (0)