您好我将excel导入数据库时遇到问题,我需要加密我的密码。现在我已经可以成功导入我的Excel到数据库,但我的密码仍然是纯文本。这是我的代码:
public function importExcel()
{
if(Input::hasFile('import_file')){
$path = Input::file('import_file')->getRealPath();
$data = Excel::load($path, function($reader) {
})->get();
if(!empty($data) && $data->count()){
foreach ($data as $key => $value) {
$insert[] =
[
'name'=>$value->name,
'password'=>$value->password,
'email'=>$value->email,
'id_branch'=>$value->id_branch,
'birth_date'=>$value->birth_date,
'birth_location'=>$value->birth_location,
'sex'=>$value->sex,
'job'=>$value->job,
'address'=>$value->address,
'telephone'=>$value->telephone,
'handphone'=>$value->handphone,
'office_address'=>$value->office_address
];
}
if(!empty($insert)){
$value['password'] = bcrypt($value['password']);
DB::table('member')->insert($insert);
return redirect('admin/'.$this->path . '/')->with('success','Success Add New Record');
}
}
}
return back();
}
答案 0 :(得分:0)
public function importExcel()
{
if(Input::hasFile('import_file')){
$path = Input::file('import_file')->getRealPath();
$data = Excel::load($path, function($reader) {
})->get();
if(!empty($data) && $data->count()){
foreach ($data as $key => $value) {
$insert[] =
[
'name'=>$value->name,
'password'=>bcrypt($value->password),
'email'=>$value->email,
'id_branch'=>$value->id_branch,
'birth_date'=>$value->birth_date,
'birth_location'=>$value->birth_location,
'sex'=>$value->sex,
'job'=>$value->job,
'address'=>$value->address,
'telephone'=>$value->telephone,
'handphone'=>$value->handphone,
'office_address'=>$value->office_address
];
}
if(!empty($insert)){
$value['password'] = bcrypt($value['password']);
DB::table('member')->insert($insert);
return redirect('admin/'.$this->path . '/')->with('success','Success Add New Record');
}
}
}
return back();
}
答案 1 :(得分:0)
在$insert[]
'password'=>bcrypt($value->password),