Fix empty option
continuous-integration/drone/tag Build is passing Details

This commit is contained in:
philipp lang 2024-04-18 19:01:54 +02:00
parent 85560ebec2
commit bf6e0fac85
1 changed files with 62 additions and 0 deletions

View File

@ -0,0 +1,62 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
foreach (DB::table('forms')->get() as $event) {
$config = json_decode($event->config);
$config->sections = array_map(function ($section) {
/** @var Collection<int, mixed> */
$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<int, mixed> */
$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()
{
//
}
};