eloquent - How to update specific rows using laravel -


i have table:

id|user_id|group_id|subject |book_id|duplicate  1| 2     |3       |history |1      |           2| 4     |3       |history |1      |  3| 5     |3       |history |1      | 

i want resulting table this:

id|user_id|group_id|subject |book_id|duplicate  1| 2     |3       |history |1      |           2| 4     |3       |history |1      |1  3| 5     |3       |history |1      |1 

i want ascending ids after lowest id duplicate column updated 1. please note: ids dynamic , using ->where(id, '>', 1); not work in cases.

so far have this

$duplicates = db::table('table')                ->where('subject', 'history')                ->where('book_id', 1)              ->skip(1)->take(1)             ->update(['duplicate' => 1]); 

the code above not work because resulting table looks this:

id|user_id|group_id|subject |book_id|duplicate  1| 2     |3       |history |1      | 1          2| 4     |3       |history |1      |  3| 5     |3       |history |1      | 

use this

db::table('table') ->where('subject', 'history') ->where('book_id', 1) ->where('id', '>', 1) ->update(['duplicate' => 1]); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -