-1

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

1 Answer 1

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');
        });
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.