Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

garethdaine's avatar

Extending Spark Registration Validation

Hey Folks,

What would you suggest is the best way to extend the Spark registration validation to validate the email address used to stop the user registering with a specific domain name?

Obviously, I don't want to directly modify the core files, just extend the functionality.

I basically need to run a check during validation to see if a user has used a specific domain name in their email, and if so, redirect/use Vue, with an error message.

Cheers

0 likes
6 replies
GianniGianni's avatar
Level 2

You can define new validation roules and inside the booted() method of the class App\Providers\SparkServiceProvider

Spark::validateUsersWith(function (Request $request) {
    return [
        'name' => 'required|max:255',
        'email' => 'required|email|unique:users,email,'.$request->input('name'),
    ];
});
1 like
garethdaine's avatar

Gianni. Is there a way to set the messages for the rules?

richardjkeys's avatar

Know it's been a while Gareth, but any pointers on changing the messages?

richardjkeys's avatar

This works:

        Spark::swap('CreateUser@validator',function($request)
        {
            $validator = $this->baseValidator($request);

            $validator->setCustomMessages([
                'phone.required' => 'The telephone number field is required.',
            ]);

            $validator->sometimes('team', 'required|max:255', function ($input) {
                return Spark::usesTeams() &&
                       Spark::onlyTeamPlans() &&
                       ! isset($input['invitation']);
            });

            $validator->sometimes('team_slug', 'required|alpha_dash|unique:teams,slug', function ($input) {
                return Spark::usesTeams() &&
                       Spark::onlyTeamPlans() &&
                       Spark::teamsIdentifiedByPath() &&
                       ! isset($input['invitation']);
            });

            return $validator;
        });
1 like

Please or to participate in this conversation.