-
-
Save varyym/88b6a040cb4e61e75fb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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