I want to import excel, and my code of controller is
$path = $request->file('file')->getRealPath();
$dataOfMember = Excel::toArray(new InterfaceMember(), $path);
$dataOfMember = $dataOfMember[0];
$insert_dataOfMember = [];
foreach ($dataOfMember as $row) {
$insert_dataOfMember[] = [
'kodeToko' => $kodeToko = session('authData')['kodeToko'],
'idMember' => DB::select(" select dbo.fcIdMember(".$this->kodeToko.", '".$row[1]."')"),
'RefereceID' => $row[0],
'KodeMember' => $row[1],
'NamaMember' => $row[2],
'JenisIdentitas' => $row[3],
'NomorIdentitas' => $row[4],
'AlamatMember' => $row[5],
'KodePos' => $row[6],
'JenisKelamin' => $row[7],
'TglLahir' => $row[8],
'NoHp' => $row[9],
'PointReedem' => $row[10],
'RpMember' => $row[11],
];
}
if (!empty($insert_dataOfMember)) {
DB::table('uplMemberDeposite')->insert($insert_dataOfMember);
}
return back()->with('success', 'Excel Data Imported successfully.');
when i running mya code, i have error that ""Array to string conversion". What should i do to slove this error? anyone please help me!
2
Answers
I think the problem lies with the line
DB::select
returns an array according to the documentation.If you did
dd(DB::select("select dbo.fcIdMember(".$this->kodeToko.", '".$row[1]."')"));
, I think you’d see the following on your screen:That’s the array that is giving you the error. You’re passing that entire array when what you’re really trying to pass is the
columnValue
part.Your query is correct. You just do a more small step: