Skip to content
Merged

Dev #3348

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/GirlsInDigitalPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ public function setAttribute($key, $value)
return parent::setAttribute($key, $value);
}

/**
* Used by Nova afterSave; not persisted to DB.
*
* @var array<string, array<string, mixed>>|null
*/
public $nonPersistedButtonUpdates;

/**
* Keep _button_updates out of the SQL UPDATE (used by Nova to pass button data to afterSave).
*/
protected static function booted(): void
{
static::saving(function (self $model): void {
$model->preserveButtonUpdatesBeforeSave();
});
}

private function preserveButtonUpdatesBeforeSave(): void
{
if (array_key_exists('_button_updates', $this->attributes)) {
$this->nonPersistedButtonUpdates = $this->attributes['_button_updates'];
unset($this->attributes['_button_updates']);
}
}

public function buttons()
{
return $this->hasMany(GirlsInDigitalButton::class, 'page_id')->orderBy('position');
Expand Down
4 changes: 2 additions & 2 deletions app/Nova/GirlsInDigitalPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public static function afterSave(NovaRequest $request, $model): void
if (! Schema::hasTable('girls_in_digital_buttons')) {
return;
}
$updates = $model->_button_updates ?? null;
$updates = $model->nonPersistedButtonUpdates ?? $model->_button_updates ?? null;
if (! is_array($updates) || empty($updates)) {
return;
}
Expand All @@ -380,7 +380,7 @@ public static function afterSave(NovaRequest $request, $model): void
report($e);
}
}
unset($model->_button_updates);
unset($model->_button_updates, $model->nonPersistedButtonUpdates);
} catch (\Throwable $e) {
report($e);
}
Expand Down
Loading