问题描述
如何编写laravel 迁移来创建点数据类型的列而无需postGIS 扩展
解决方法
<?php
namespace App\Grammer;
use Illuminate\Database\Schema\Grammars\PostgresGrammar;
use Illuminate\Support\Fluent;
/**
* Extended version of PostgresGrammar with
* support of 'point' data type in Postgres.
*/
class ExtendedPostgresGrammar extends PostgresGrammar
{
/**
* Create the column definition for a spatial Point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typePoint(Fluent $column)
{
return $column->type;
}
}
My Migration is
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Grammer\ExtendedPostgresGrammar;
class UpdateTableAddressesAddColumnPoints extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// register new grammar class
DB::connection()->setSchemaGrammar(new ExtendedPostgresGrammar());
$schema = DB::connection()->getSchemaBuilder();
$schema->table('addresses',function (Blueprint $table) {
$table->point('geo_location')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('addresses',function (Blueprint $table) {
$table->dropColumn('geo_location');
});
}
}