如何在Laravel 5.6的默认注册表单中添加自定义字段? [英] How to add custom field in default registration form of Laravel 5.6?

查看:165
本文介绍了如何在Laravel 5.6的默认注册表单中添加自定义字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Laravel 5.6 应用程序之一中,我需要在默认注册表单中添加更多字段.

In one of my Laravel 5.6 application, I need to add a few more fields in the default registration form.

因此,我仅在默认注册表格 registration.blade.php 中添加了一个字段来测试[phone_no],还添加了 phone_no RegisterController ,但是当我单击注册"按钮时,它显示以下错误:

So I've added only one field to test [phone_no] in the default registration form registration.blade.php, and also add phone_no RegisterController, but when I click on register button it shows the following errors:

"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();
    });
}

这是 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'],
    ]);
}

所以我想我错过了一些事情.谁能告诉我如何在 Laravel 5.6 默认注册表单中添加一个/多个字段并成功保存这些字段... -谢谢

So I think I miss something. Can anyone tell me how can I add one/more fields in the Laravel 5.6 default registration form and save those field successfully... - Thanks

推荐答案

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

Please add your custom field in below way.

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

In your model add the your custom field in protected $fillable=['name', 'email', 'password', 'created_by', 'phone_no'] in your model

这篇关于如何在Laravel 5.6的默认注册表单中添加自定义字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆