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

تعليقات

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

How to Create Treeview with Bootstrap and jQuery

jQuery Datatables with PHP, MySQL and AJAX Example

How to Add Images to Dropdown List using jQuery