Hi I am working on a project Laravel where I need to update record in database by fetching last(latest) record against foreign key, The scenario is fetch latest record(row) and if its specific column (amendments_to) has NULL value update it with some string else insert a new record. Below is my code what it does is always updates last row only no matter what the value in amendments_to column is.
OrderResponse::where('send_id', $id)
->orderBy('id', 'desc')
->take(1)
->update(['amendments_to' => $request->comment]);