问题描述
我正在尝试使用 for
包让用户导入 csv 或 excel 文件并将其导入数据库。
我是 Laravel 的新手,所以我不太确定如何解决这个问题。
我不断收到错误消息:
ErrorException 未定义的数组键“FirsT” http://127.0.0.1:8000/import-form
CSV 示例数据
df
路线:
df<-structure(list(Name = c("test","a","nb","c","r","f",NA,"d","ee","test","value","b")),row.names = c(NA,-13L),class = c("tbl_df","tbl","data.frame"))
导入PatientController.PHP
df1
Maatwebsite\Excel
导入PatientModel.PHP
FirsT,LAST,EMAIL,PHONE,DEPARTMENT,LOCATION
test name 1,teast last 1,test@mail.com,123-123-1231,test department,test location
import-form.blade.PHP
Route::post('/import-form',[ImportPatientController::class,'importForm'])->name('import.file');
解决方法
PHP 中的数组键区分大小写。
我认为如果您将 $row['FIRST']
更改为 $row['first']
,问题将得到解决!