1. In Laravel 6, after applying soft deletes to a model, re-inserting a record causes a unique key conflict. See Figure 1.

PS E:\wwwroot\object> php artisan theme-store:theme:install E:\wwwroot\object\resources\views\brooklyn 971c4f4d-097b-4a84-a914-0ef00b6e69da blade --force
Delete theme
Install theme to data repository
Installation failed because: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '971c4f4d-097b-4a84-a914-0ef00b6e69da-apps/internal/back-top/app.' for key 'theme_asset2_theme_id_asset_key_unique' (SQL: insert into `theme_asset2` (`asset_key`, `theme_id`, `mime_type`, `created_at`, `content`, `schema`, `category`, `updated_at`) values (apps/internal/back-top/app.json, 971c4f4d-097b-4a84-a914-0ef00b6e69da, application/json, 2022-08-26 01:59:53, {
"title": "Back to top",
"description": "Adds a button to the page that returns to the top of the page, improving user experience."
}
, ?, unknown, 2022-08-26 01:59:53))
2. The reason is that after applying soft deletes, when you use the delete method on a model instance, the current date and time are written to the deleted_at field. At the same time, soft-deleted records are automatically excluded from query results.
ThemeAsset::where('theme_id', $themeId)->delete();
3. Because the record was not hard deleted, a unique key conflict occurs when writing a new record.
4. Query results automatically exclude soft-deleted records. Therefore, you need to use the withTrashed method to retrieve models including the soft-deleted ones. Then use the forceDelete method to permanently delete the soft-deleted models from the database.
ThemeAsset::withTrashed()->where('theme_id', $themeId)->forceDelete();
5. The record is successfully hard deleted, and re-inserting no longer throws an error. See Figure 2.

