i have 2 type of code use laravel eloquent to insert data to database. but the problem is laravel cant use the column name as array. here its the code
//manual
$insert = new AlarmActive;
$insert->$primaryKey = $value[$primaryIndex];
$insert->Specific_problem = $value[1];
$insert->Managed_object = $value[2];
$insert->save();
//with for
$insert = new AlarmActive;
for($i=0; $i<count($column); $i++){
$insert->$column[$i] = $value[$i];
}
$insert->save();
the first code with tag //manual is doing fine and can input to database. but when i try with for (//with for) laravel say it to convertion the array to string. my $column[$i] values is the database column name and i can echo it.
so my question how to make the second code run.
EDIT here it my code to fill $column variable
function inputAlarmActive($filenamewithoutex)
{
$line = Storage::get( 'public/'.$filenamewithoutex[0].'/show_alarm_active.log' );;
$fLine = explode("\n", $line);
$size = count($fLine);
$data = array();
$arr_data;
$temp;
$column;//Kolom tabel database
$value;//Nilai Kolom
$batas = "Appl. addl. info";
$tabel = "show_alarm_active";
$primaryKey ="Alarm_ID";
$primaryIndex =0;
for ($i=0; $i < $size; $i++) {
if (strpos($fLine[$i], " :") !==false) {
$temp[] = $fLine[$i];
}
}
$this->ArrayData($temp, $batas, $tabel,$primaryKey,$primaryIndex);
}
function ArrayData($temp, $batas, $tabel, $primaryKey, $primaryIndex)
{
global $fLine, $size,$data;
for ($i=0; $i < count($temp) ; $i++) {
$data = explode(":", $temp[$i]);
$kolom = trim($data[0], " ");
$kolomdot = preg_replace('/[^A-Za-z0-9\-\\ ]/', '', $kolom);
if(strpos($kolomdot, ' ')){
$column[]=str_replace(' ', '_', $kolomdot);
}
else{
$column[]=str_replace('-', '_', $kolomdot);
}
$value[]=$data[1];
if (strpos($temp[$i], $batas)!==false) {
$this->InsertData($column, $value, $tabel,$primaryKey, $primaryIndex);
unset($column);
unset($value);
}
}
}
first function "input alarm active" use to read the file with parameter the name of the folder. in this function im explode ":" to get data, the left of ":" will be the column, and the right will be the value.
second function is arraydata to fill the column array variable and fill value array variable.
third class is insert data, the code to insert to database.
here its the output of
for($i=0; $i<count($column); $i++){
echo $column[$i]." : ".$value[$i]."<br>";
}
here its the dd() output of $column
array:14 [▼
0 => "Alarm_ID"
1 => "Specific_problem"
2 => "Managed_object"
3 => "Severity"
4 => "Cleared"
5 => "Clearing"
6 => "Acknowledged"
7 => "Ack_user_ID"
8 => "Ack_time"
9 => "Alarm_time"
10 => "Event_type"
11 => "Application"
12 => "Identif_appl_addl_info"
13 => "Appl_addl_info"
]
here the dd() of $value
array:14 [▼
0 => " 103736\r"
1 => " 70025 - POSSIBLE SECURITY THREAT IN NETWORK ELEMENT\r"
2 => " fsFragmentId=PamAlarmThrower,fsFragmentId=security,fsClusterId=clusterRoot\r"
3 => " 4 (minor)\r"
4 => " no\r"
5 => " manual\r"
6 => " no\r"
7 => " N/A\r"
8 => " N/A\r"
9 => " 2017-06-03 08"
10 => " x4 (quality of service)\r"
11 => " fsFragmentId=PamAlarmThrower,fsFragmentId=security,fsClusterId=clusterRoot\r"
12 => " \r"
13 => " \r"
]

$columnvariable?$columnand$valuearraydd($column)and show us the output?