Files
hstream/database/migrations/2026_01_10_120521_create_comments_table.php
2026-01-10 15:02:14 +01:00

39 lines
1.0 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
{
// Remame old table from laravelista/comments
Schema::rename('comments', 'comments_old');
Schema::create('comments', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('parent_id')->nullable()->constrained('comments')->cascadeOnDelete();
$table->morphs('commentable'); // What is being commented on
$table->text('body');
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('comments');
// Revert to old table from laravelista/comments
Schema::rename('comments_old', 'comments');
}
};