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.
$last_row = Model::orderBy('id', 'desc')->first();
$new_object = new Model()
$new_object.attr1 = $last_row->id + 1
$new_object.attr2 = $last_row->id + 2
Using this method your are searching for a key that is lower than the key associated on line 1. So even if another object is created before line 2, it will not be considered on your line 2 search.
$new_object = Model::create(); $last_row = Model::where("id","<",$new_object")->orderBy('id', 'desc')->first(); $new_object->attr1 = $last_row->id + 1 $new_object->attr2 = $last_row->id + 2 $new_object->save()
You could also use the timestamp to search for the newest created object. If your model have timestamps.