This is kind of embarrassing, probably silly, but it might help someone. I was going to call this post "Freshman Problem and Solution," but it wasn't descriptive enough.
backstory is that I created a table with a dynamic number of columns based on an array drawn from an excel spreadsheet that the user uploads. Column titles in the database are simply 'col0', 'col1', 'col2' etc
So, DB::table()->insert() wants an associative array, which is a really pain in the patootie for an otherwise elegant system. Since I usually work with numerical array or arrays of objects, this threw me for a loop. This is what I was doing. Below is incorrect:
for($x=0; $x<count($cells); $x++){
for($y=0; $y<count($cells[$x]); $y++){
$insert[$x][] = array('col'.$x => $cells[$x][$y]);
}
}
This yielded the annoying an probably obvious to many flaw that I spent way to long on.
$insert[$x] in general was looking something like this:
[0 => ['col0' => 'mystery data'],
1 => ['col1' => 'more mystery data'],
2 => ['col2' => 'etc']]
where I needed to look like this for this insert
['col0' => 'mystery data',
'col1' => 'more mystery data',
'col2' => 'etc']
So here's what I did to fix it. You don't have to kick me, I already kicked myself.
for($x=0; $x<count($cells); $x++){
for($y=0; $y<count($cells[$x]); $y++){
$cells[$x]['col'.$y] = $cells[$x][$y];
unset($cells[$x][$y]);
}
}
DB::table('my_table')->insert($cells);
The insert ran without issue. Thank you Google. Hopefully this helps someone.