I would like to update record and check if not exists in table, but the problem is if I check exists, it worked but I cannot even update the one record that I selected because it already exist.
Here my code
$app->post('/update_function', function($request, $response, $args) {
$exists = $this->db->table('functions')->where('project_id', '=', $request->getParam('project_id'))
->where('function_number', '=', $request->getParam('function_number'))
->exists();
if(!$exists) {
$query = $this->db->table('functions')
->where('function_id', '=', $request->getParam('function_id'))
->update([
'project_id' => $request->getParam('project_id'),
'function_number' => $request->getParam('function_number'),
'function_text' => $request->getParam('function_text')
]);
if($query) {
echo "Function was updated";
}
}else {
echo "Can not update duplicate function number";
}
});