Update existing images frontend

Hey.

I’m trying to handle new images and mix them with the existing ones. I’m a bit unsure about how to add the new images. I thought I could do it like adding to an array, but it didn’t work that way. I also tried turning the existing images into an array using ->toArray(), but that just cleared out all the images from the ->image() field.

Maybe someone give me a hint.

          try {
              $name = crc32($upload['name'].microtime()). '_' . $upload['name'];
              $file = $submission->createFile([
                'source'   => $upload['tmp_name'],
                'filename' => $name,
                'template' => 'upload',
                'content' => [
                    'date' => date('Y-m-d h:m')
                ]
              ]);
              $submissionImages = $submission->content()->image();
              // $submissionImages = $submission->content()->image()->toArray();
              $submissionImages[] = $file;
              $submission->update([
                'image' => $submissionImages,
              ]);
              $success = 'Your file upload was successful';
            } catch (Exception $e) {
              $alerts[$upload['name']] = $e->getMessage();
            }

I assume you want to update a files field called image with the newly uploaded file:

$submissionImages = $submission->content()->image()->toFiles();

$submissionImages = $submissionImages->add($file);
$kirby->impersonate('kirby');
$page->update(['image' => $submissionImages->pluck('UUID', ',')]);