Skip to content

Commit

Permalink
Output new Laravel 11 geo column types
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary committed Dec 18, 2024
1 parent 3df7f03 commit 3c8581b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Generators/MigrationGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ protected function buildDefinition(Model $model): string
if (!empty($columnAttributes) && !$this->isIdColumnType($column->dataType())) {
$column_definition .= ', ';

if (in_array($column->dataType(), ['geography', 'geometry'])) {
$columnAttributes[0] = Str::wrap($columnAttributes[0], "'");
}

if (in_array($column->dataType(), ['set', 'enum'])) {
$column_definition .= json_encode($columnAttributes);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/Lexers/ModelLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ModelLexer implements Lexer
'enum' => 'enum',
'float' => 'float',
'fulltext' => 'fullText',
'geography' => 'geography',
'geometry' => 'geometry',
'geometrycollection' => 'geometryCollection',
'increments' => 'increments',
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/Generators/MigrationGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ public static function modelTreeDataProvider()
['drafts/foreign-key-on-delete.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/foreign-key-on-delete.php'],
['drafts/nullable-columns-with-foreign.yaml', 'database/migrations/timestamp_create_comments_table.php', 'migrations/nullable-columns-with-foreign.php'],
['drafts/omits-length-for-integers.yaml', 'database/migrations/timestamp_create_omits_table.php', 'migrations/omits-length-for-integers.php'],
['drafts/geometry-columns.yaml', 'database/migrations/timestamp_create_locations_table.php', 'migrations/geometry-columns.php'],
];
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/drafts/geometry-columns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
models:
Location:
name: string:100
description: text nullable
coordinates: geography:point,4326
positions: geometry:point,0

31 changes: 31 additions & 0 deletions tests/fixtures/migrations/geometry-columns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('locations', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->text('description')->nullable();
$table->geography('coordinates', 'point', 4326);
$table->geometry('positions', 'point', 0);
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('locations');
}
};

0 comments on commit 3c8581b

Please sign in to comment.