database/migrations/2016_02_10_193507_add_country_to_company_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCountryToCompanyTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('companies', function (Blueprint $table) {
$table->integer('country_id')->unsigned()->index()->nullable();
$table->foreign('country_id')->references('id')->on('countries')->onDelete('restrict')->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('companies', function (Blueprint $table) {
$table->dropForeign('companies_country_id_foreign');
$table->dropIndex('companies_country_id_index');
$table->removeColumn('country_id');
});
}
}