简体   繁体   English

如何在Sentry Laravel中上传user.csv

[英]How to upload a user.csv in Sentry Laravel

I'm currently using Sentry in my Laravel project. 我目前在Laravel项目中使用Sentry。 And Goodby CSV which uses PDO for uploading CSV files and adding the data to my database. 还有Goodby CSV,它使用PDO上传CSV文件并将数据添加到我的数据库中。

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? 还是有更好的替代CSV上传?

或者,您可以使用以下软件包: https : //github.com/Maatwebsite/Laravel-Excel无需配置数据库,您可以导入CSV文件来管理数据。

I made it, i was able to upload my users using laravel-excel ( thanks to H Davila) here's what i did; 我做到了,我能够使用laravel-excel上传我的用户(感谢H Davila),这就是我所做的;

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

    ));
    }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM