<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void {
        Schema::create('tbl_news', function (Blueprint $table) {
            $table->increments('news_id');
            $table->string('news_title', 255);
            $table->mediumText('news_content');
            $table->mediumText('news_content_short');
            $table->string('photo', 255);
            $table->dateTime('published_at')->nullable()->index();
            $table->integer('category_id')->unsigned()->index();
            $table->integer('author_id')->unsigned()->nullable()->index();
            $table->string('encode_title', 255)->index();
            $table->string('img_alt', 255)->nullable();
            $table->string('meta_title', 255)->nullable();
            $table->mediumText('meta_keyword')->nullable();
            $table->mediumText('meta_description')->nullable();
            $table->string('type', 50)->default('general');
            $table->unsignedBigInteger('views')->default(0);

            $table->foreign('category_id')->references('category_id')->on('tbl_category');
            $table->foreign('author_id')->references('author_id')->on('tbl_authors')->nullOnDelete();
        });
    }
    public function down(): void { Schema::dropIfExists('tbl_news'); }
};
