Where are you calling validatePwdForUser from?
Custom Validator Not Firing
I'm trying to use a custom validator on a user profile page that manages a password change. The validator doesn't seem to be getting called.
This is not the only custom validator in the solution. I have a few others and those are all called as I expect them to be.
If there's a better way to validate the current user's password on a password change, I'll be happy to hear about it. As it is, here's what I'm doing...
I created a custom validator class called ExtendedValidator.php. Into that, I've placed a few new functions. The one that isn't being called is coded as follows:
public function validatePwdForUser($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'pwd_for_user');
$userId = array_shift($parameters);
$where[] = [
['id', '=', $userId],
['password', '=', bcrypt($value)]
];
dd($where);
return (1 == Users::where($where)->count());
}
When I put a dd($parpmeters) as the first line in that method, it never dies and dumps. This tells me that the method is never getting called.
I think my controller should call that method because in the controller, I have the following code:
public function update(Request $request, Profile $profile)
{
$authUser = Auth::user();
$hasPassword = (strlen($request->input('new_password')) > 0);
$validations = [];
if ($hasPassword) {
$validations [] = [
'password' => 'required|pwd_for_user:' . $authUser->id,
'new_password' => 'required|confirmed|min:6|password_complexity:2,ipd,ultera,helpdesk'
];
}
$this->validate($request, $validations);
When I put a dd($validations) right before the $this->validate() call, it dumps the 2 validations I expect to see. The first one should call my custom validation method. Actually, the second one should call a different custom validation method and that doesn't seem to be firing, either.
In my AppServiceProvider.php file, I reference my custom validator class:
public function boot()
{
Validator::resolver(
function($translator, $data, $rules, $messages, $customAttributes) {
return new ExtendedValidator($translator, $data, $rules, $messages, $customAttributes);
}
);
What have I done wrong?
Thanks!
Please or to participate in this conversation.