<?php

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

    class BlockEntry extends Migration
    {

        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('block_entry', function (Blueprint $table) {
                $table->unsignedInteger('block_id');
                $table->unsignedInteger('entry_id');
                $table->integer('position')->nullable();
                $table->primary(['block_id', 'entry_id']);

                $table->foreign('block_id')->references('id')
                    ->on('blocks')->onDelete('CASCADE')->onUpdate('CASCADE');
                $table->foreign('entry_id')->references('id')
                    ->on('entries')->onDelete('CASCADE')->onUpdate('CASCADE');
            });
        }

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

    }
