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

تعليقات

المشاركات الشائعة من هذه المدونة

BlueHost Web Hosting Review: Secrets Revealed for Shared Hosting

How to Create Treeview with Bootstrap and jQuery

Submit Form using jQuery AJAX and PHP without Page Refresh