thijsai
thijsai

Reputation: 1785

Add MySQL geospatial Point column in Laravel 4 migration

  1. How do I add a Point column in my Laravel 4 migration for a MySQL database?
  2. Is it possible to setup database independent migrations using a check if mysql and check if postgres statement? And if so how could I go about doing that?

I've tried:

public function up()
{
    Schema::create('meetings', function(Blueprint $table) {
        $table->increments('id');

        $table->string('title');
        $table->text('description');
        $table->enum('category',[0,1,2,3,4])->index();

        $table->unsignedInteger('owner_id');
        $table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');

        $table->dateTime('start_date');
        $table->dateTime('end_date');

        $table->timestamps();
    });
    DB::raw("ALTER TABLE meetings ADD COLUMN geolocation POINT"); 
}

But this does not seem to work.

Upvotes: 2

Views: 1225

Answers (1)

Razor
Razor

Reputation: 9835

You should use statement method:

DB::statement("ALTER TABLE meetings ADD COLUMN geolocation POINT");

Update

About the second question, you can access to database.php file like this:

if (Config::get('database')['default'] === 'mysql'){
    // mysql 
}else if (Config::get('database')['default'] === 'pgsql'){
    // PostgreSQL
}

Upvotes: 6

Related Questions