Arrays, saving multiple

Posted 2 months ago by theUnforgiven

I have the following, and I want to save then as individual rows as they will be related to a block

array:5 [▼
  "name_of_blocks" => array:4 [▼
    0 => null
    1 => "test1"
    2 => "test2"
    3 => "test3"
  ]
  "no_units" => array:4 [▶]
  "no_of_floors" => array:4 [▼
    0 => null
    1 => "2"
    2 => "2"
    3 => "3"
  ]
  "lift" => array:4 [▼
    0 => "Please Select"
    1 => "no"
    2 => "no"
    3 => "yes"
  ]
  "facilities" => array:1 [▼
    0 => "visitor_parking"
  ]
]

How does one save these again I'm forgot and having a major meltdown about it lol

I have tried the following but this fails:

$data = $request->except('_token');

        for($i = 0; $i < count($data); $i++){
            $block = new Blocks;
            $block->name_of_blocks = $name[$i];
            $block->no_units = $units[$i];
            $block->no_of_floors = $floors[$i];
            $block->lift = $lift[$i];
            $block->facilities = $facilities[$i];
            $block->save();
        }

Please sign in or create an account to participate in this conversation.