2

I'm currently using Sentry in my Laravel project. And Goodby CSV which uses PDO for uploading CSV files and adding the data to my database.

Here's my controller to upload the users, it works but the problem is on how to hash the password.

public function postUploadUsers()
{
    $csv = Input::file('file');
    $pdo = new PDO('mysql:host=localhost;dbname=******', '******', '*******');

    $config = new LexerConfig();
    $lexer = new Lexer($config);

    $interpreter = new Interpreter();

    $interpreter->addObserver(function(array $columns) use ($pdo) {
        $stmt = $pdo->prepare('INSERT INTO users (email,username,password,permissions,activated,activated_at,code,first_name,last_name,cname) VALUES (?,?,?,?,?,?,?,?,?,?,?)'); 

        $stmt->execute($columns);
    }); 

    $lexer->parse($csv, $interpreter);
    return Redirect::to('home');
}

Or There is a better alternative CSV upload?

Frankie_C
  • 4,764
  • 1
  • 13
  • 30
Caloyz
  • 21
  • 3

2 Answers2

0

Or you can use this package: https://github.com/Maatwebsite/Laravel-Excel no need to configure a DB and you can import CSV files for manage data.

  • Thanks for your reply H. Davila, if i use laravel-excel, how can i hash the password using sentry hashing. – Caloyz Aug 14 '15 at 03:55
0

I made it, i was able to upload my users using laravel-excel ( thanks to H Davila) here's what i did;

public function home()  {
Excel::filter('chunk')->load('user.xls')->chunk(250, function($reader)
{ // get data
$results = $reader->get();
foreach($results as $row)
{
// do stuff
Sentry::register(array(
     //sentry register syntax

    ));
    }
}
}
Caloyz
  • 21
  • 3