gpt4 book ai didi

php - 如何在 Laravel 5.6 的默认注册表单中添加自定义字段?

转载 作者:行者123 更新时间:2023-12-03 23:13:24 25 4
gpt4 key购买 nike

在我的其中之一 Laravel 5.6 应用程序,我需要在默认注册表中添加更多字段。
所以我只添加了一个字段来测试默认注册表中的 [phone_no] registration.blade.php ,并添加电话号码 注册 Controller ,但是当我单击注册按钮时,它显示以下错误:

"SQLSTATE[HY000]: General error: 1364 Field 'phone_no' doesn't have a default value (SQL: insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) values (Jahid Hossain, jahid.cse18@gmail.com, $2y$10$wYg6jAihCz.v09PUXngF/ekjNvZgxb4Rq4GI3i.glfzXt37oGnbSO, 2018-04-20 06:24:27, 2018-04-20 06:24:27))
所以这里是 迁移文件 代码:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->string('status')->default('active');
$table->string('created_by')->default('SYSTEM');
$table->string('modified_by');
$table->string('phone_no');
$table->rememberToken();
$table->timestamps();
});
}
这是 的代码注册 Controller :
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
'created_by' => $data['email'],
'phone_no' => $data['phone_no'],
]);
}
所以我想我错过了一些东西。谁能告诉我如何在 中添加一个/多个字段Laravel 5.6 默认注册表单并成功保存这些字段...
  • 感谢
  • 最佳答案

    请按以下方式添加您的自定义字段。

    在您的模型中添加您的自定义字段 protected $fillable=['name', 'email', 'password', 'created_by', 'phone_no']在你的模型中

    关于php - 如何在 Laravel 5.6 的默认注册表单中添加自定义字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49935424/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com