I ask this question to find the best practice for this.
DB::table('owners')
->where('property_id',$id)
->update(array('person_id'=>$owner));
The problem is that the table ownersmay not have a row to update. In this case, I need to do INSERT INTOinstead UPDATE.
My problem is that I have to run 2 requests each time, one to check if a row exists, and another one to UPDATEeither INSERT INTO. Is it correct to run 2 queries each time? Is there a better way to achieve this? I need to support fast processes for the user.
UPDATE: The table ownersis the middle table of many, many relationships. Sorry, I can’t use ON DUPLICATE KEY.
Makis source
share