<?php

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

class CreateAccreditationsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('accreditations', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('learning_product_id');
            $table->string('credits')->nullable();
            $table->dateTime('date_start', 0)->nullable();
            $table->dateTime('date_end', 0)->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::table('accreditations', function (Blueprint $table) {
            $table->foreign('learning_product_id')->references('id')->on('learning_products')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('accreditations', function (Blueprint $table) {
            $table->dropForeign('accreditations_learning_product_id_foreign');
        });

        Schema::dropIfExists('accreditations');
    }
}
