title: update last record of matching condition in single query
body: <p>I want to update last record of matching condition.i am getting more than one result in code so i did it different way.</p>
  
  <pre><code>$u = user_payments::where('id', $id)-&gt;where('staff_id', $staffId)-&gt;orderBy('id','desc')-&gt;first();
  $up = user_payments::where('id', $u-&gt;id)-&gt;update(['transaction_id' =&gt; $transaction_id]);
  </code></pre>
  
  <p>here i have to query two times so it call DB two times as i want to optimise the query, I tries as above but i want to it in single query... How can i do this ? Thanks.</p>