php - 某些数据无法插入数据库
问题描述
当新用户填写注册表并点击提交时,我可以使用 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。谢谢你
解决方案
PASSWORD 是数据库的保留关键字。尝试重命名该列。
推荐阅读
- sqlite - Flutter:为什么这个函数里面的方法没有访问数据库变量?
- java - 有没有办法找到安装在 OS X 上的 Java 版本的完整列表?
- java - 我应该在这个程序中传递什么参数以避免 java.lang 错误?
- r - 将另一列添加到数据框中,通过一个标签定义多个值的标签以绘制分组条形图
- python - 尽管成功登录,但用户身份验证失败
- html - CSS悬停在邻居上以切换属性
- python - scipy.optimize.curve_fit,参数全部返回 1
- java - 使用带有 Java 的 Tesseract 从图像中提取文本时出错
- oracle - 有什么方法可以在字典表中找到所有内置的 oracle 函数?
- javascript - 将 easylist 与 chrome declarativeNetRequest 一起使用