id(); $table->foreignId('listing_id')->constrained('listings')->cascadeOnDelete(); $table->foreignId('seller_id')->constrained('users')->cascadeOnDelete(); $table->foreignId('buyer_id')->constrained('users')->cascadeOnDelete(); $table->timestamp('last_message_at')->nullable(); $table->timestamps(); $table->unique(['listing_id', 'buyer_id']); $table->index(['seller_id', 'last_message_at']); $table->index(['buyer_id', 'last_message_at']); }); Schema::create('conversation_messages', function (Blueprint $table): void { $table->id(); $table->foreignId('conversation_id')->constrained('conversations')->cascadeOnDelete(); $table->foreignId('sender_id')->constrained('users')->cascadeOnDelete(); $table->text('body'); $table->timestamp('read_at')->nullable(); $table->timestamps(); $table->index(['conversation_id', 'created_at']); $table->index(['conversation_id', 'read_at']); }); } public function down(): void { Schema::dropIfExists('conversation_messages'); Schema::dropIfExists('conversations'); } };