Laravel - Update all fields of a large table

2

I have the following problem ...

I am migrating a system, and in the same I own a table of clients

This table has a field called " cli_password ", which represents the client password

To use Laravel authentication I had to create a " password " column

Now I need to replicate all the passwords in the " cli_password " column to the " password " column.

But I can not just duplicate the cli_password column and rename it to password

Or perform a simple SQL to update the password column by taking cli_ename because the cli_enable field has no encryption.

So I'm forced to go through all the fields of the table, doing the due Hash.

But the table has more than 40,000 records, and every time I query the screen returns blank, I can only select 5,000 records through the "chunk"

Would anyone have a suggestion or some other method more efficient than making multiple pages and updating their records?

    
asked by anonymous 04.09.2014 / 22:16

2 answers

4

Hello,

The code you will make is very simple.

$users = User::wherePassword(null)->take(5000);
foreach($users as $user){
    $user->password = Hash::make($user->cli_senha);
    $user->save();
}
    
04.09.2014 / 22:26
1

You can create a migration to rename the column and update the passwords:

Schema::table('users', function($table) {
    $table->renameColumn('cli_senha', 'password');
});

foreach(User::all() as $user) {
    $user->password = Hash::make($user->password);
    $user->save();
}

link

    
05.09.2014 / 05:02