<?php

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

class CreateCreditUserTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
       Schema::create('credit_user', function(Blueprint $table)
    		{
    			$table->increments('id');
    			$table->mediumInteger('quantity');
          $table->date('date');
          $table->integer('user_id')->unsigned()->index();
          
          $table->integer('credit_id')->unsigned()->index();
          $table->integer('reservation_id')->unsigned()->index();

          $table->softDeletes();
          $table->timestamps();
    		});
        
        Schema::table('credit_user', function(Blueprint $table) {
          $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
          //$table->foreign('credit_id')->references('id')->on('credits')->onDelete('cascade'); 
          $table->foreign('reservation_id')->references('id')->on('reservations')->onDelete('cascade'); 
        });
    }

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