#Submitting form from Section header action
1 messages · Page 1 of 1 (latest)
$record will be null on create. If you want to submit the form on both create and edit use $context
->action(function (array $data, Config $record, string $context) {
if ($context === 'edit') {
$record->fill($data);
$record->save();
}
if ($context === 'create') {
Config::create($data);
}
})
@astral cosmos I ended up getting it working by redefining the record since it's always the same, not sure if this is the right approach?
->action(function (array $data) {
$this->record=Config::firstOrNew([
'config_type' => 'global_styling',
]);
$existing_data=$this->record->config_value;
$updated_data = array_merge($existing_data[0], $data);
$this->record->config_value = [$updated_data];
$this->record->save();
})