CODE
$validator = Validator::make($request->all(), [
'name' => [
'required',
'string',
'max:255',
Rule::unique('users')->where(function ($query) use ($request) {
return $query->whereRaw('LOWER(name) = ?', strtolower($request->name));
})->ignore($request->user()->id),
'regex:/^[a-zA-Z0-9_-]+$/',
],
]);
So the issue is, I want to validate based on lowercase. So, regardless of what the user types or what is in the DB, it looks for the same string all in the same case. The reason for this is users might type JohnSmith for their username and we respect the case, but we do not want another user with the name johnsmith or JOHNsmith.
What is wrong with the above query?