-1

How to write laravel migration to create column with point data type without postGIS extension

sufyan
  • 19
  • 3

1 Answers1

0
<?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');
        });
    }
}
sufyan
  • 19
  • 3