-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4103 from GCTC-NTGC/bug/improve-unique-email-vali…
…dation Bug - Improve unique email validation
- Loading branch information
Showing
19 changed files
with
1,388 additions
and
1,032 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\GraphQL\Validators; | ||
|
||
use Illuminate\Validation\Rule; | ||
use Nuwave\Lighthouse\Validation\Validator; | ||
|
||
final class UpdateUserInputValidator extends Validator | ||
{ | ||
/** | ||
* Return the validation rules. | ||
* | ||
* @return array<string, array<mixed>> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'email' => [ | ||
'sometimes', | ||
'nullable', | ||
/** | ||
* Note: Ignore the email for the user passed | ||
* in when executing the mutation so it is not | ||
* included in the unique check. This is required | ||
* for allowing a user to be updated while the email | ||
* remains the same. | ||
* | ||
* REF: https://laravel.com/docs/9.x/validation#rule-unique | ||
*/ | ||
Rule::unique('users', 'email')->ignore($this->arg('id'), 'id'), | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Return the validation messages | ||
*/ | ||
public function messages(): array | ||
{ | ||
return [ | ||
'email.unique' => 'This email address is already in use', | ||
]; | ||
} | ||
} |
Oops, something went wrong.