Files
blog/Database/Migrations/2016_09_05_085644_create_comments.php

52 lines
1.3 KiB
PHP
Executable File

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateComments extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('user_id')
->nullable(true)
->default(null)
->comment('When comment was inserted by logged user, save his ID here');
$table->integer('content_id');
$table->string('email');
$table->string('name');
$table->text('content');
$table->boolean('approved');
$table->foreign('content_id')
->references('id')
->on('contents')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('set null')
->onUpdate('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('comments');
}
}