database/migrations/2020_12_28_103405_create_category_user_table.php
<?php
use EscolaLms\Core\Migrations\EscolaMigration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateCategoryUserTable extends EscolaMigration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->create('category_user', function (Blueprint $table) {
$table->unsignedBigInteger('user_id')->index();
$table->unsignedBigInteger('category_id')->index();
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
// $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
$table->primary(['user_id', 'category_id']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('category_user');
}
}