simedkom/database/migrations/2025_12_12_082036_create_news_table.php

40 lines
1.2 KiB
PHP

<?php
use App\Enums\NewsStatus;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('news', function (Blueprint $table) {
$table->id();
$table->foreignId('author_id')->constrained('users')->cascadeOnDelete();
$table->string('title', 200);
$table->string('slug', 200)->index();
$table->text('content');
$table->text('excerpt');
$table->string('link', 50)->nullable();
$table->unsignedInteger('views')->default(0)->index();
$table->enum('status', NewsStatus::values())->comment(NewsStatus::comment())->index();
$table->timestamp('published_at')->nullable()->index();
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('news');
}
};