mardi 20 juillet 2021

laravel transaction vs database statement

what is the differences of following two:

DB::update(
    'update users set votes = 0 where votes < 0'
);
DB::transaction(function () {
    DB::table('users')->where('votes', '<' , 0)->update(['votes' => 0]);
});

Official Laravel doc says

The update method should be used to update existing records in the database

But transaction seems more handful that can react to exceptions.

So in what scenarios one is better than the other?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3x1D8Ux
via IFTTT

Aucun commentaire:

Enregistrer un commentaire