我绝对不是laravel的新手。有人可以帮助我逐行理解这些代码,这是做什么的,等等。这是用于将excel文件导入数据库。
对于控制器:
public function import(Request $request)
{
$import = Excel::import(new ResidentImport, request()->file('import_file'));
return redirect('/importing')->with('success', 'Imported Successfully!');
}
该模型有什么用?
public function model(array $row)
{
return new Resident([
'resident_fname' => $row[0],
'resident_lname' => $row[1],
'resident_mi' => $row[2],
'resident_dob' => \PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['3']),
'role' => $row[4],
'resident_age' => $row[5],
'resident_address' => $row[6],
'resident_contact' => $row[7],
'resident_email' => $row[8],
'resident_purok' => $row[9],
'resident_status' => $row[10],
'resident_gender' => $row[11],
'resident_religion' => $row[12],
'ResidentVoter_status' => $row[13],
]);
}