CodeIgniter Forums
Unque Validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Unque Validation (/showthread.php?tid=89931)



Unque Validation - titounnes - 02-10-2024

I have a tabel with theese folowing columns
users: id, email
in my table i have an record like this
id : 1
email: [email protected]

in model i create a valdation rule 
'username' => 'required|is_unique[users.email,id,{id}]'

in controller

Code:
$data = ['id'=>1, 'email'=>'[email protected]'];
$id = $data->id  
if($model->where('id', $d)->set($data)){
  ///
} else {
dd($model->errors);
}
when I run my code,  have result
The email field must contain a unique value.. 

Can someone help me?

[quote pid="416090" dateline="1707574434"]
Solved,
in the model the id must be included in the validation rule
[/quote]