39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
use App\Enums\ArticleStatus;
|
|
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('articles', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->foreignId('author_id')->constrained('users')->cascadeOnDelete();
|
|
$table->string('title', 200);
|
|
$table->string('slug')->unique();
|
|
$table->text('excerpt');
|
|
$table->text('content');
|
|
$table->enum('status', [ArticleStatus::values()])->default(ArticleStatus::PUBLISH)->comment(ArticleStatus::comment());
|
|
$table->timestamp('published_at')->nullable();
|
|
$table->unsignedInteger('views')->default(0);
|
|
$table->timestamp('created_at')->useCurrent();
|
|
$table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
|
|
$table->softDeletes();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('articles');
|
|
}
|
|
};
|