Eloquent offers a handy way of passing stuff to the database
$table_name = new TableName;
$table_name->column_name = "some data";
$table_name->save();
I've got quite a lot of data from a form that needs to be validated, so I was wondering if it was possible to replace the column name with a variable, so I can put it in some loop, and get the names and data from arrays.
$table_name->$columns[$i] = $data[$i];
(though I suppose not written in that way)
Update
In the end I've gone with the following:
$table_name = new TableName;
$nameArray=[
1 => 'form-name-1',
...
];
$columnArray=[
1 => 'column_name_1',
...
];
for($i=1;$i<=count($nameArray);$i++){
if(logic logic logic) $table_name->{$columnArray[$i]} = $_POST[$nameArray[$i]];
else $table_name->{$columnArray[$i]} = NULL;
}
$table_name->save();