40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
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('posts', function (Blueprint $table) {
|
|
$table->id();
|
|
$table->string('title');
|
|
$table->text('body');
|
|
$table->text('excerpt'); // توضیحات مختصر
|
|
$table->string('slug')->unique();
|
|
$table->unsignedBigInteger('author_id'); // نویسنده
|
|
$table->foreign('author_id')->references('id')->on('users')->onDelete('cascade');
|
|
$table->unsignedBigInteger('category_id'); // دسته بندی
|
|
$table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
|
|
$table->string('featured_image')->nullable(); // تصویر شاخص
|
|
$table->integer('views')->default(0); // تعداد بازدید
|
|
$table->integer('likes')->default(0); // تعداد لایک
|
|
$table->timestamp('published_at')->nullable(); // تاریخ انتشار
|
|
$table->timestamps();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Reverse the migrations.
|
|
*/
|
|
public function down(): void
|
|
{
|
|
Schema::dropIfExists('posts');
|
|
}
|
|
};
|