Skip to content

Commit c5b8ecf

Browse files
authored
Value not nullable on extract (#31)
* Do not use updateOrCreate, so we can set value when creating translatable string * Fix tests * Fix styling --------- Co-authored-by: jyrkidn <2447042+jyrkidn@users.noreply.github.com>
1 parent 65c772d commit c5b8ecf

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/ExtractTranslatableStrings.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,21 @@ public function missingKey(string $scope, string $name, string $key, bool $isHtm
125125
{
126126
TranslatableString::flushEventListeners();
127127

128-
$translatableString = TranslatableString::updateOrCreate([
128+
$translatableString = TranslatableString::firstOrNew([
129129
'scope' => $scope,
130130
'name' => $name,
131-
], [
132-
'key' => $key,
133-
'is_html' => $isHtml,
134131
]);
135132

136-
if ($translatableString->wasRecentlyCreated) {
133+
// Set/update fields that should always be updated
134+
$translatableString->key = $key;
135+
$translatableString->is_html = $isHtml;
136+
137+
// Only set value on creation (not on update)
138+
if (! $translatableString->exists) {
137139
$translatableString->value = $this->getValue($key);
138140
}
141+
142+
$translatableString->save();
139143
}
140144

141145
public function getAllFunctions(): Collection

tests/Feature/Filament/TranslatableStringResource/Pages/ListTranslatableStringsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
Notification::assertNotified(
108108
Notification::make()
109109
->success()
110-
->title('Import was successful')
110+
->title(__('filament-translatable-strings::admin.import completed'))
111111
);
112112

113113
$this->assertDatabaseCount(TranslatableString::class, 2);

0 commit comments

Comments
 (0)