Skip to content

Commit 4fd773f

Browse files
committed
fix mass assignment error
1 parent 7c56ae1 commit 4fd773f

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/Entities/Items/Draft/BaseDraftResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ public static function getFormActions(): Actions
100100
}
101101

102102
if (static::enableDelete()) {
103-
$actions[] = static::getDeleteAction()->extraAttributes(attributes: ['class' => 'w-full']);
103+
$actions[] = static::getDeleteAction()->extraAttributes(attributes: ['class' => 'w-full']);
104104
}
105105

106106
if (static::enableEdit()) {
107107
$actions[] = static::getEditAction()->extraAttributes(attributes: ['class' => 'w-full']);
108108
}
109-
109+
110110
return Actions::make($actions);
111111
}
112112

src/Entities/Items/Draft/Pages/BaseEditDraft.php

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,36 @@ public function mutateFormDataBeforeFill(array $data): array
4848
}
4949

5050
protected function handleRecordUpdate(Model $record, array $data): Model
51-
{
52-
/** @var Model&TranslatableContract $record */
53-
if (! $this->lang) {
54-
return parent::handleRecordUpdate($record, $data);
55-
}
51+
{
52+
/** @var Model&TranslatableContract $record */
53+
if (! $this->lang) {
54+
return parent::handleRecordUpdate($record, $data);
55+
}
5656

57-
if (! property_exists($record, 'translatedAttributes')) {
58-
return parent::handleRecordUpdate($record, $data);
59-
}
57+
if (! property_exists($record, 'translatedAttributes')) {
58+
return parent::handleRecordUpdate($record, $data);
59+
}
6060

61-
$translation = $record->translations()->firstOrNew([
62-
'locale' => $this->lang,
63-
]);
61+
// Save translation manually
62+
$translation = $record->translations()->firstOrNew([
63+
'locale' => $this->lang,
64+
]);
6465

65-
foreach ($record->translatedAttributes as $attr) {
66-
if (array_key_exists($attr, $data['translations'][$this->lang])) {
67-
$translation->setAttribute($attr, $data['translations'][$this->lang][$attr]);
68-
}
66+
foreach ($record->translatedAttributes as $attr) {
67+
if (array_key_exists($attr, $data['translations'][$this->lang] ?? [])) {
68+
$translation->setAttribute($attr, $data['translations'][$this->lang][$attr]);
6969
}
70-
$translation->save();
70+
}
71+
$translation->save();
7172

72-
$record->update($data);
73+
// Remove 'translations' from data before update
74+
unset($data['translations']);
75+
76+
$record->update($data);
77+
78+
return $record;
79+
}
7380

74-
return $record;
75-
}
7681

7782
public function mutateFormDataBeforeSave(array $data): array
7883
{

0 commit comments

Comments
 (0)