I am trying to import an Excel file into my table using the MaatWebsite package. But every time I get errors like these:
Illegal string offset 'Emp'
I am following this tutorial. And here is the code I have tried:
$path = $request->file('attendance_data')->getRealPath();
$data = Excel::load($path)->get();
if($data->count() > 0)
{
foreach($data->toArray() as $key => $value)
{
foreach($value as $row)
{
$insert_data[] = array(
'employee_card' => $row['Emp'],
'attendance_date' => $row['Date'],
'attendance_time' => $row['On'],
);
}
}
if(!empty($insert_data))
{
DB::table('attendance_logs')->insert($insert_data);
}
Any help will be appreciated