php - Laravel4: Chunk function not working with model save() -
I have a query to select all the users and have a password hash and save that model. Since there is a large data in DB, I think I will try the Chuck () function. My query looks like this,
$ users = User :: where ('password', '! =', '0') -> Select ('password')) - & gt; Share ($ 50, Function ($ user) {foreach ($ user as user user) {$ user-> password = hash :: create ($ user- & gt; password); $ user- & gt; Save ();}}); It does not save any models. When I try to dump after the $ user variable to save then this update displays the value, but even when I check DB It is monolithic. I tried to see if trying to use try to hold and transaction to kill any exception during this process, nothing helped Any help will be appreciated. Also, I'm not $ protected on the password field.
Can you just tell which line is being updated in that loop? needed? No? Well known it does not know either, so it runs updates ... where the id is empty ;)
just add id to Select the cloud and it will work (unless you have any magic in Saving event, etc.):
$ users = User: Select: ('password (,'! = ',' 0 ') -> Select (Arrays (' id ',' password ')) - & gt; Chuck (50, function ($ user) {foreach ($ User $ user $) {$ user- & gt; password = hash :: create ($ user- & Gt; password); $ user-> Save ();}});
Comments
Post a Comment