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?
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
));
}
}
}