I'm trying to import some excel data to my database,but the date format from excel are null in php.
$this->validate($request, ['file' => 'required|mimes:xls,xlsx']);
$path = $request->file('file')->getRealPath();
$data = Excel::load($path)->formatDates( true, 'd-m-Y' )->get();
if($data->count() > 0) {
return view('employes.data')->with('data', $data);
foreach($data->toArray() as $key) {
foreach($key as $row) {
$insert[] = array(
"nume" => $row['nume'],
'cnp' => $row['cnp'],
'functie' => $row['functie'],
'data_angajare' => $row['data_angajare'],
'ssm' => $row['ssm'],
'psi' => $row['psi'],
'fisa_aptitudini' => $row['fisa_aptitudini'],
'pram' => $row['pram'],
);
}
}
if(!empty($insert)) {
DB::table('employes')->insert($insert);
}
}
result
[{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null},{"nume":"test","cnp":"test","functie":"test","data_angajare":null,"ssm":null,"psi":null,"fisa_aptitudini":null,"pram":null,"0":null}]
excel
nume cnp functie data_angajare ssm psi fisa_aptitudini pram
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
test test test 18/10/1000 18/10/1000 10/10/1000 10/10/1000 10/10/1000
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire