mardi 29 décembre 2015

Laravel 5.2 update/insert batch similar to Codeigniter's update_batch/insert_batch()

Does laravel have an update batch functionality similar to Codeigniter?

Codeigniter uses $this->db->update_batch('mytable', $data, 'title'); to do a batch update. More info could be found here.

But as for laravel's update, it seems that it could only do a single transaction. I feel that this is kind of bad when you have multiple rows to update wherein it will be inside a for loop. Something similar to this:

foreach ($rows => $row) {
    DB::table('users')->where('id', $row['row_id'])->update(['votes' => 1]);
}

For atleast you get the picture, right?

If you'll look into this code, your database could get knock out pretty much as it keeps on connecting unlike the update_batch(), only a single transaction is being throw.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire