I am new in Laravel. I want to insert data from an array into the database. My data is inserted into the database but when the data exist in the database, the same data uploads into the database. I want to insert only new data that is not in the database.
$str=$this->entry();
$end=$this->exit_entry();
$st=array_chunk($str,5);
$ex=array_chunk($end,5);
$result=array();
foreach($st as $v1){
$tmp = array(
'Employee_id'=>$v1[0],
'Employee_name'=>$v1[1],
'Date' => $v1[2],
'Day' =>$v1[3],
'Time1' => $v1[4]
);
foreach($ex as $v2){
if($v2[1] == $v1[1] && $v2[0] == $v1[0] && $v2[2] == $v1[2] && $v2[3] == $v1[3] ){
$tmp['Time2']=$v2[4];
}
}
$result[] = $tmp;
}
foreach($result as $res) {
$res1 = EmployeeList::insert($res);
}
//var_dump($res1);