From bf6e0fac8533fd21093b900558279d2da8a0a9dc Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 18 Apr 2024 19:01:54 +0200 Subject: [PATCH] Fix empty option --- ..._04_16_233540_add_hasemptyoption_field.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 database/migrations/2024_04_16_233540_add_hasemptyoption_field.php diff --git a/database/migrations/2024_04_16_233540_add_hasemptyoption_field.php b/database/migrations/2024_04_16_233540_add_hasemptyoption_field.php new file mode 100644 index 00000000..7cf27baa --- /dev/null +++ b/database/migrations/2024_04_16_233540_add_hasemptyoption_field.php @@ -0,0 +1,62 @@ +get() as $event) { + $config = json_decode($event->config); + $config->sections = array_map(function ($section) { + /** @var Collection */ + $fields = $section->fields; + $section->fields = collect($fields)->map(function ($field) { + if ($field->type === 'GroupField') { + $field->has_empty_option = false; + $field->empty_option_value = ''; + } + return $field; + })->all(); + + return $section; + }, $config->sections); + DB::table('forms')->where('id', $event->id)->update(['config' => json_encode($config)]); + } + + foreach (DB::table('formtemplates')->get() as $event) { + $config = json_decode($event->config); + $config->sections = array_map(function ($section) { + /** @var Collection */ + $fields = $section->fields; + $section->fields = collect($fields)->map(function ($field) { + if ($field->type === 'GroupField') { + $field->has_empty_option = false; + $field->empty_option_value = ''; + } + return $field; + })->all(); + + return $section; + }, $config->sections); + DB::table('formtemplates')->where('id', $event->id)->update(['config' => json_encode($config)]); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +};