title: Laravel get "unique" row from mysql
body: <p>I have a special scenario to fetch "unique" row.</p>
  
  <p>Let's say the database is like below</p>
  
  <pre><code>| id | userid | value | others  |
  |----|--------|-------|---------|
  | 1  | 111    | 10    | string1 |
  | 2  | 112    | 30    | string2 |
  | 3  | 112    | 30    | string3 |
  | 4  | 113    | 50    | string4 |
  </code></pre>
  
  <p>what I want to achieve is to fetch the unique rows based on the "userid" so I'am able to sum all values.</p>
  
  <p>the expect output row can be either <code>id: 1 2 4</code> or <code>1 3 4</code> (both is acceptable for this special case because <code>same id guarantees same value</code>, or in general, get just one row from those row with same <code>userid</code>. ), so the sum will be <code>90</code>.</p>
  
  <p>Note: <code>DB</code> is extended from <code>Eloquent\model</code></p>
  
  <p>My old approach is to get DB::unique('userid'); then for each userid DB::where('userid', $id)->value('value'), add the result to sum; I just believe there might be a better approach. </p>