首页 > 解决方案 > 某些数据无法插入数据库

问题描述

当新用户填写注册表并点击提交时,我可以使用 dd($var) 获取我需要的所有数据。但是,在插入数据库时​​ laravel 说Cannot insert the value NULL into column 'password'。为什么 laravel 在插入数据库时​​没有得到我的密码?

我不知道我在这里做错了什么。帮我 ..

这是我的RegisterController.php

protected function create(array $data)
{
    $pw_hash     = Hash::make($data['Password']);
    $uuid4       = Uuid::uuid4();


    $a = DB::table('Person.Person')->insert(array(
        'PersonId'      => $uuid4->toString(),
        'PersonName'    => $data['PersonName'],
        'Email'         => $data['Email'],
        'IsActive'      => false,
        'IsLoginActive' => false,
        'PasswordSalt'  => substr($pw_hash, 7, 22),
        'PasswordHash'  => sha1($pw_inpt.''.$pw_salt),
        'IsMale'        => $data['IsMale'],
        'Email'         => $data['Email'],
        'Phone'         => $data['Phone'],
        'LoginName'     => $data['Email'],
        'PersonName'    => $data["NamaDepan"]." ".$data['NamaBelakang'],
        'EmailVerifiedAt'   => date('Y-m-d'),
        'EmailVerified'     => false,
        'EmailVerificationCode'=> Hash::make(rand(0,100)),
        'password'=> 'aaaapass',
    ));

    dd($a);
}

这是我的User.php模型

class User extends Authenticatable{
use Notifiable;

protected $table        = 'Person.Person';
// protected $username     = 'Email';

public $incrementing    = false;
protected $primaryKey   = 'PersonId';

const CREATED_AT = 'CreatedDate';
const UPDATED_AT = 'ModifiedDate';

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'PersonId',
    'Email',
    'Phone',
    'IsMale',
    'password',
    'IsActive',
    'Position',
    'LoginName',
    'kencur',
    'ClusterId',
    'BirthDate',
    'BirthPlace',
    'PersonName',
    'PersonImage',
    'PasswordSalt',
    'PasswordHash',
    'ModifiedDate',
    'IsLoginActive',
    'EmailVerified',
    'WhatsappNumber',
    'EmailVerifiedAt',
    'EmailVerificationCode',
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password',
    'PasswordHash',
    'PasswordSalt',
    'remember_token',
];

public function getEmailForPasswordReset() {
    return $this->Email;
} 
}

这就是 laravel 所说的:

Cannot insert the value NULL into column 'password', table 'Assess2.Person.Person'; column does not allow nulls. INSERT fails. (SQL: insert into [Person].[Person] ([PersonId], [PersonName], [Email], [IsActive], [IsLoginActive], [PasswordSalt], [PasswordHash], [IsMale], [Phone], [LoginName], [EmailVerifiedAt], [EmailVerified], [EmailVerificationCode], [password]) values (f6377aeb-df36-4f38-aef5-40c7a2240cc5, has sutenan, namadcvbepan@gmail.com, 0, 0, CTDdYYCXHULY4ad8jQJ9WO, $2y$10$CTDdYYCXHULY4ad8jQJ9WOmVqCILEuJPHSgffLlVW5SK7b7Q4qMpy, true, 55, namadcvbepan@gmail.com, 2019-03-04, 0, $2y$10$vcHlXQgukHomPI.FJZe2XOyl0lJd3Lo5rDqVN5SU8gY3UloPLsr.C, aaaapass))

我正在使用 laravel 5.7。谢谢你

标签: phpdatabaselaravel

解决方案


PASSWORD 是数据库的保留关键字。尝试重命名该列。


推荐阅读