How to upload a user.csv in Sentry Laravel

292 Views Asked by At

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?

2

There are 2 best solutions below

0
Caloyz On BEST ANSWER

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

    ));
    }
}
}
1
Helmer Davila On

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.