I have to following customized validation
Validator::extend('uniqueFirstAndLastName', function ($attribute, $value, $parameters, $validator) {
$count = DB::table('people')->where('firstName', $value)
->where('lastName', $parameters[0])
->where('id', '<>', $parameters[1])
->count();
return $count === 0;
});
How do I call this rule with the 2nd parameter since $parameters expects an array?
This does not work:
return Validator::make($data, [
'firstName' => "uniqueFirstAndLastName:{$data['lastName]},{$data['id']}"
]
23000then the record exists and you notify the user that those credentials have been taken. Create abinarycolumn that contains a hash of first and last name, make it unique, simply insert and catch the exception. Everything else will fail.$dataparams into validator rule directly - they are already there in$validator->getData()