Skip to content

Latest commit

 

History

History
29 lines (26 loc) · 748 Bytes

entity-checker.md

File metadata and controls

29 lines (26 loc) · 748 Bytes

Entity checker

Checks if current value is unique, best solution for user emails.

Usage example

class UserRequest extends RequestFilter
{
    const SCHEMA = [
        'email' => 'data:email',
    ];

    const VALIDATES = [
        'email' => [
            // other email field validation rules
            ['\Vvval\Spiral\Validation\Checkers\EntityChecker::isUnique', UserSource::class, 'email'],
        ],
    ]
}

2nd rule argument is RecordSource class name,
3rd one is the field, which is used to match uniqueness.

If you're editing existing user, don't forget to set user entity to a request (validator) context:

/**
 * @var UserRequest $request
 * @var User        $user
 */
$request->setContext($user);