Bcrypt在Laravel 5.4中将文件excel上传到数据库时的密码

时间:2017-08-29 07:08:54

标签: php excel laravel laravel-5

您好我将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();
  }

2 个答案:

答案 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),