| subject (unique) | visible |
when data post from view, if only change visible column when I update data will be reject because the subject is same means exist in database, so I have to add one step select data first and check if $_POST['subject']
equal original row then only update visible column.
is this correct or is there any more convenience method?
$result = $this->tag_table
->where('id', $id)
->get()->toArray()[0];
$subject = $result['subject'];
if (!empty($result)) {
$result = $this->tag_table
->where('subject', $_POST['subject'])
->get()->toArray()[0];
if (!empty($result) && ($subject != $_POST['subject'])) {
$error_message = "error_message: tag, duplicate subject exists";
} else {
$this->tag_table
->where('id', $id)
->update(array(
'visible' => $_POST['visible'],
'subject' => $_POST['subject'],
));
}
} else {
$error_message = "error_message: tag, id not exists";
}