I'm trying to update a table using Maatwebsite/Laravel-Excel.
public function import(Request $request)
{
if($request->file('imported-file'))
{
$path = $request->file('imported-file')->getRealPath();
$data = Excel::load($path, function($reader)
{
})->get();
if(!empty($data) && $data->count())
{
foreach ($data->toArray() as $row)
{
if(!empty($row))
{
$dataArray[] =
[
//'name' => $row['name'],
'age' => $row['age'],
'phone' => $row['phone'],
//'created_at' => $row['created_at']
];
}
if(!empty($dataArray))
{
//Item::insert($dataArray);
DB::table('items')
->where('name', $row['name'])->update($dataArray);
return view('imported')->with('success', 'Course updated');
}
}
}
}
}
But its giving error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: update items set 0 = 20 where name = james
Here's my csv
name,age,phone
James,20,888839939
Joseph,54,3444444
Hanson,30,99999999
The above is the csv file i'm trying to update.
items
set0
= 20 wherename
= james – James Bondze