A
A
Alexander2016-11-07 11:10:19
Laravel
Alexander, 2016-11-07 11:10:19

How to make a nested array of images?

There is a form:

//1
<input type="file" name="image[]">
<input type="text" name="name[]">
//2
<input type="file" name="image[]">
<input type="text" name="name[]">

In the first input I select 2 files, in the second 1.
fae33b2fae3f49888cb3228c40ff1157.png
I send the data to the server:
"name" => array:2 [▼
    0 => "First"
    1 => "gjghj"
  ],
"image" => array:3 [▼
    0 => UploadedFile {#215 ▶}
    1 => UploadedFile {#216 ▶}
    2 => UploadedFile {#217 ▶}

How can I make the image array look like this
"image" => array:3 [▼
    0 => [
           0 => UploadedFile {#215 ▶}
           1 => UploadedFile {#215 ▶}
]
    1 => [
            0 => UploadedFile {#215 ▶}
]

So that you can then sort the data and save it where you need it.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question