1

Created a FormRequest named ValidationRegister to slightly change the standard registration controller. Since I saw most of the checks in the Request.

Here is the validation itself:

public function rules()
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'surname' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
            'gender' => ['nullable', 'string', 'max:10'],
            'birthday' => ['nullable', 'string'],
            'rules' => 'accepted',
        ];
    }

The essence of the question is how to replace the validation in the controller

Standard validation:

protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

There were various attempts to do this, even reached the change of registration trait

1 Answer 1

1

In the file App/Http/Controllers/Auth/RegisterController, you can overwrite the trait method register. For your custom logic to work, you probably also need to change the create method, to save your new validated fields.

public class RegisterController {    

    public function register(ValidationRegister $request)
    {
        event(new Registered($user = $this->create($request->validated())));

        $this->guard()->login($user);

        return $this->registered($request, $user)
            ?: redirect($this->redirectPath());
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.