How to perform update and save operations in eloquent which are dependent on the last row of a table?
<p>I want to perform an operation similar to the following where the attributes of the object I'm creating depends on the attributes of previous object.</p>

<pre><code>$last_row = Model::orderBy('id', 'desc')-&gt;first();  
$new_object = new Model()
$new_object.attr1 = $last_row-&gt;id + 1
$new_object.attr2 = $last_row-&gt;id + 2
$new_object-&gt;save()
</code></pre>

<p>How do you perform the necessary locking in Eloquent to ensure that line 1 is executed by only one transaction at a time? </p>

<p>What other code do I need to add or edit to ensure that two objects do not have the same attr1 and attr2 if line 1 is performed for both objects before either one of the objects is saved.</p>