diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 31841bc..dceb795 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -594,7 +594,7 @@ class Plugin extends Model // Get all attributes except id and uuid // Use toArray() to get cast values (respects JSON casts) $attributes = $this->toArray(); - unset($attributes['id'], $attributes['uuid']); + unset($attributes['id'], $attributes['uuid'], $attributes['trmnlp_id']); // Handle render_markup_view - copy file content to render_markup if ($this->render_markup_view) { diff --git a/tests/Unit/Models/PluginTest.php b/tests/Unit/Models/PluginTest.php index aa9a28e..749fb62 100644 --- a/tests/Unit/Models/PluginTest.php +++ b/tests/Unit/Models/PluginTest.php @@ -821,6 +821,26 @@ test('plugin duplicate copies all attributes except id and uuid', function (): v ->and($duplicate->render_markup_view)->toBeNull(); }); +test('plugin duplicate sets trmnlp_id to null to avoid unique constraint violation', function (): void { + $user = User::factory()->create(); + + $original = Plugin::factory()->create([ + 'user_id' => $user->id, + 'name' => 'Plugin with trmnlp_id', + 'trmnlp_id' => 'test-trmnlp-id-123', + ]); + + $duplicate = $original->duplicate(); + + // Refresh to ensure casts are applied + $original->refresh(); + $duplicate->refresh(); + + expect($duplicate->trmnlp_id)->toBeNull() + ->and($original->trmnlp_id)->toBe('test-trmnlp-id-123') + ->and($duplicate->name)->toBe('Plugin with trmnlp_id (Copy)'); +}); + test('plugin duplicate copies render_markup_view file content to render_markup', function (): void { $user = User::factory()->create();