#How to properly save array of inputs into table?

1 messages · Page 1 of 1 (latest)

ancient spoke
#

I have an array of inputs. The structure looks like this

array:3 [▼ // app\Http\Controllers\WhiteLabelTemplate\GenerateWhiteLabelController.php:182
  "title" => array:2 [▼
    593 => "Title"
    594 => "Title"
  ]
  "price" => array:2 [▼
    593 => "1235"
    594 => "12345"
  ]
  "description" => array:2 [▼
    593 => "Title"
    594 => "Title"
  ]
]

This is how I save the code to the table

foreach ($validated as $key1 => $values) {
            // dd($values[array_keys($values)[0]]);
            // dd($validated, $key1, $values, array_keys($values));

            WlService::updateOrCreate(
                ['wl_category_id' => $wlCategory->id],
                [
                    'user_id' => Auth::user()->id,
                    'name' => $values[array_keys($values)[$i]] ?? null,
                    'price' => $values[array_keys($values)[$i]],
                    'description' => $values[array_keys($values)[$i]],
                    'accelerate_service_id' => array_keys($values)[$i],
                    'wl_config_images' => null, // null for now
                ]
            );
            $i++;
        }

Is there a much better way of approaching this? I have been stuck in this for a while and it doesnt loop correctly

#

The way I saved it is wrong