在我的Laravel 5.6应用程序中,我需要在默认注册表单中添加更多字段。
因此,我仅在默认注册表单registration.blade.php中添加了一个字段来测试[phone_no] ,还添加了phone_no RegisterController,但是当我单击register按钮时,它显示以下错误:
"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))
Run Code Online (Sandbox Code Playgroud)
因此,这是迁移文件代码:
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();
});
}
Run Code Online (Sandbox Code Playgroud)
这是RegisterController的代码:
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'],
]);
}
Run Code Online (Sandbox Code Playgroud)
所以我想我想念一些东西。谁能告诉我如何在Laravel 5.6默认注册表单中添加一个/多个字段并成功保存这些字段...-谢谢
小智 7
请通过以下方式添加您的自定义字段。
在模型中添加自定义字段中protected $fillable=['name', 'email', 'password', 'created_by', 'phone_no']的模型
| 归档时间: |
|
| 查看次数: |
1978 次 |
| 最近记录: |