I have to update record ignoring the current record ie I have implement uniqueness on two column company_id and user_id while insert record the code working perfectly but when I update its not I stuck how can I implement Here is the code
Validator::extend('ValidateUser', function ($attribute, $value, $parameters) use ($company_id, $user_id) {
$msgs = CustomReports::where('parent_company', $company_id)->where('user_id',$user_id)->get()->count();
if ($msgs > 0) {
return false;
} else {
return true;
}
});
Validator::replacer('ValidateUser', function ($translator, $data, $rules, $messages) {
return "Custom report is already assign to this user against parent company";
});
$this->validate($request,[
'parent_company_id' => 'required',
'user' => 'required|ValidateUser',
'reporting_company_id' => 'required',
'bifurcation' => 'required',
]);
解决此问题的一种方法是对创建和更新用户使用不同的验证
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.