【问题标题】:Illuminate \ Database \ QueryException (HY000) SQLSTATE[HY000]: General error: 1364 Field 'verifyToten' doesn't have a default valueIlluminate \ Database \ QueryException (HY000) SQLSTATE[HY000]:一般错误:1364 字段“verifyToten”没有默认值
【发布时间】:2019-03-24 06:03:06
【问题描述】:

我想在数据库中创建并存储一个验证令牌,以便在注册后激活用户的帐户。但我收到了上述错误。 你能帮忙吗?

用户表

       Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('phone',10)->unique();
        $table->string('password');
        $table->string('verifyToten');
        $table->boolean('is_active')->default(0);
        $table->timestamp('email_verified_at')->nullable();
        $table->rememberToken();
        $table->timestamps();
    });

用户模型

   protected $fillable = [
    'name', 'email', 'phone', 'password','verifyToten'
];

注册控制器

        return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'phone' => $data['phone'],
        'password' => bcrypt($data['password']),
        'verify_token' => Str::random(40),
    ]);

【问题讨论】:

  • 您正在尝试填写verify_token,但您的数据库字段为verifyToken

标签: mysql email-verification laravel-5.7


【解决方案1】:

在您的用户迁移中,您的字段名称是 $table->string('verifyToten');,而在您的注册控制器中,您正在为 'verify_token' => Str::random(40) 保存值,将控制器中的 verify_token 更改为 verifyToten

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-01
    • 2021-05-23
    • 2019-05-09
    • 2019-09-10
    • 2021-01-04
    • 2020-09-06
    • 2020-06-21
    • 2019-05-19
    相关资源
    最近更新 更多