Skip to content

Instantly share code, notes, and snippets.

@varyym
Created November 2, 2015 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varyym/88b6a040cb4e61e75fb5 to your computer and use it in GitHub Desktop.
Save varyym/88b6a040cb4e61e75fb5 to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateCompaniesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('companies', function(Blueprint $table)
{
$table->increments('id');
$table->string('title')->unique();
$table->string('address');
$table->string('phone');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('companies');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateContactsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('contacts', function(Blueprint $table)
{
$table->increments('id');
$table->string('firstName');
$table->string('lastName');
$table->string('photo');
$table->date('birthday');
$table->string('phone');
$table->string('address');
$table->integer('country_id')->unsigned();
$table->foreign('country_id')->references('id')->on('countries');
$table->text('comment');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('contacts');
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateCompanyContactTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('company_contact', function(Blueprint $table)
{
$table->increments('id');
$table->integer('company_id')->unsigned()->index();
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
$table->integer('contact_id')->unsigned()->index();
$table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade');
$table->unique(['contact_id', 'company_id'], 'unique_pair');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('company_contact');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment