Gabotronix
6 months ago

'confirmationKey' doesn't have a default value when registering user

Posted 6 months ago by Gabotronix

Hi everybody, I'm trying to stablish my custom user verification system, basically I addded a confirmationKey field into my laravel user model, the I changed my register method to add the confirmationKey when an user is created. Issue is for some reason the value isn't added and I'm getting the following error:

SQLSTATE[HY000]: General error: 1364 Field 'confirmationKey' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) values (igyguiiuiug, [email protected], y$HlQbAOyhSCuif5exWZdz/.pCcXAmkWqCdXirNwvY.9/KPDtI5X14S, 2019-04-10 13:26:17, 2019-04-10 13:26:17))

This is pretty weird as you can see in the create method of my RegisterContoller I have added confirmationKey to the create method:

//RegisterController
protected function create(array $data)
    {
        $confirmationKey = Str::random(32);
        //var_dump('confirmationKey: '.$confirmationKey);
        
        $mailData = [
            'confirmationKey' => $confirmationKey,
            'sender' => env('MAIL_FROM'),
            'subject' => 'ConfirmaciĆ³n de registro en '.env('APP_NAME'),
        ];

        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'confirmationKey' => $confirmationKey
        ]);

        Mail::to( $data['email'] )->send(new UserMail1($mailData));

        return $user;
    }

When I do a var_dump I can clearly see confrmationKey is exists and is a string.

what's wrong with my code?

Please sign in or create an account to participate in this conversation.