<?php

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

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
                        $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->string('seo_title')->unique();
            $table->string('meta_description')->unique();
            $table->string('opengraph_title')->unique();
            $table->string('opengraph_image')->unique();
            $table->json('data');
            $table->enum('state', [
              Post::POST_DRAFT,
              Post::POST_LIVE,
              Post::POST_ARCHIVED,
            ]);
            $table->integer('author')->unsigned()->nullable();
            $table->foreign('author')->references('id')->on('users')->onDelete('cascade');
            $table->timestamps();
        });
    }

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