我知道这个问题已经问过很多次了,但是没有人解释在模型中进行验证时如何获取ID。
'email' => 'unique:users,email_address,10'
我的验证规则在模型中,因此如何将记录的ID传递给验证规则。
这是我的模特/用户
protected $rules_update = [
'email_address' => 'required|email|unique:users,email_address,'.$id,
'first_name' => "required",
'last_name' => "required",
'password' => "required|min:6|same:password_confirm",
'password_confirm' => "required:min:6|same:password",
'password_current' => "required:min:6"
];
模型/基本模型
protected $rules = array();
public $errors;
/*
* @data: array, Data to be validated
* @rules: string, rule name in model
*/
public function validate($data, $rules = "rules") {
$validation = Validator::make($data, $this->$rules);
if($validation->passes()) {
return true;
}
$this->errors = $validation->messages();
return false;
}