<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateNewsBlocksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('news_blocks', function (Blueprint $table) {
            $table->unsignedInteger('news_id');
            $table->unsignedInteger('block_id');
            $table->unsignedInteger('position');
            $table->primary(['news_id', 'block_id'], 'PK_block_news');

            $table->foreign('news_id')
                ->references('id')->on('news')
                ->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('block_id')
                ->references('id')->on('blocks')
                ->onDelete('CASCADE')->onUpdate('CASCADE');

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('news_blocks');
    }
}
