简体   繁体   English

添加字段注册页面Laravel 5.4

[英]Add field register page Laravel 5.4

I'm looking to add a field on my registration page using Laravel Auth. 我想使用Laravel Auth在我的注册页面上添加一个字段。 The basic user table contain the name, email, password. 基本用户表包含名称,电子邮件,密码。 I want to add an right field. 我想添加一个正确的字段。

So I've eddited the create_users_table.php migration file to 所以我编辑了create_users_table.php迁移文件到

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->string('password');
        $table->integer('right_id');
        $table->rememberToken();
        $table->timestamps();
    });
}

and my registercontroller.php to 和我的registercontroller.php

protected function create(array $data)
{
    return User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'right_id' => 0,
        'password' => bcrypt($data['password']),
    ]);
}

But it doesn't works. 但这是行不通的。 I still have this error about right_id . 我仍然有关于right_id错误。 Seem that the value is not send to the database. 似乎该值未发送到数据库。

Any fix/help? 任何修复/帮助吗? Thanks 谢谢

Have you specify your right_id in User model class like the code sample below? 您是否right_idUser模型类中指定了right_id ,例如以下代码示例? If you forget to declare the additional field in the $fillable , the value wont save into database. 如果忘记在$fillable声明其他字段,则该值不会保存到数据库中。

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password', 'right_id'
    ];
}

on your registercontroller.php try to use 在您的registercontroller.php上尝试使用

'right_id' => '0' , instead of 'right_id' => 0 , 'right_id' => '0' ,而不是'right_id' => 0

If you just want to have '0' as a default value for 'right_id' you can also specify it on your creat_users_table.php like this 如果只想将'0'作为'right_id'的默认值,则也可以像这样在creat_users_table.php中指定它

$table->integer('right_id')->default(0);

Then redo the migration 然后重做迁移

Use like this 这样使用

  $data['right_id']  = 0;
  $data['password'] = bcrypt($data['password']);
  return User::create($data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM