*/ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class LinkCustomersToGroups extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('customers_group_customers', function (Blueprint $table) { // Set a link between customers groups and customers. $table ->integer('customers_group_id') ->unsigned(); $table ->foreign('customers_group_id') ->references('id') ->on('customers_groups') ->onDelete('cascade'); $table ->integer('customer_id') ->unsigned(); $table ->foreign('customer_id') ->references('id') ->on('customers') ->onDelete('cascade'); // Prevent the inclusion of duplicated entries. $table->unique(['customers_group_id', 'customer_id']); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('customers_group_customers'); } }