如何在laravel中注册用户时设置初始值?

如何在laravel中注册用户时设置初始值?,laravel,registration,Laravel,Registration,我试图在用户注册时设置一个字符串(16)值作为用户ID。(这不会改变,必须是唯一的。它有62^16种可能性,所以我不担心在这一点上发生碰撞。) 我还想设置另一个随机字符串作为激活码。当用户注册时,我无法设置此选项。我已经注释掉了导致问题的行(如果让它们运行,则插入它们,但忽略所有其他数据) 这是二传手应该去的地方吗 User.php(模型) 我可能会重写save()方法: 非常感谢你。我选择了后者。第一个不起作用:) <?php use Illuminate\Auth\UserInter

我试图在用户注册时设置一个字符串(16)值作为用户ID。(这不会改变,必须是唯一的。它有62^16种可能性,所以我不担心在这一点上发生碰撞。)

我还想设置另一个随机字符串作为激活码。当用户注册时,我无法设置此选项。我已经注释掉了导致问题的行(如果让它们运行,则插入它们,但忽略所有其他数据)

这是二传手应该去的地方吗

User.php(模型)


我可能会重写save()方法:


非常感谢你。我选择了后者。第一个不起作用:)
<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {


//    public function __construct()
//    {
//        $this->attributes['mdbid'] = str_random(16);
//        $this->attributes['key'] = str_random(11);
//    }

/**
 * @var string
 */
protected $primaryKey = 'mdbid';
/**
 * @var bool
 */
public $incrementing = false;

// Don't forget to fill this array
/**
 * @var array
 */
protected $fillable = array('name', 'dob', 'email', 'username', 'password');

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'users';

/**
 * The attributes excluded from the model's JSON form.
 *
 * @var array
 */
protected $hidden = array('password');

/**
 * Get the unique identifier for the user.
 *
 * @return mixed
 */
public function getAuthIdentifier()
{
    return $this->getKey();
}

/**
 * Get the password for the user.
 *
 * @return string
 */
public function getAuthPassword()
{
    return $this->password;
}

/**
 * Get the token value for the "remember me" session.
 *
 * @return string
 */
public function getRememberToken()
{
    return $this->remember_token;
}

/**
 * Set the token value for the "remember me" session.
 *
 * @param  string  $value
 * @return void
 */
public function setRememberToken($value)
{
    $this->remember_token = $value;
}

/**
 * Get the column name for the "remember me" token.
 *
 * @return string
 */
public function getRememberTokenName()
{
    return 'remember_token';
}

/**
 * Get the e-mail address where password reminders are sent.
 *
 * @return string
 */
public function getReminderEmail()
{
    return $this->email;
}

public function setPasswordAttribute($password)
{
    $this->attributes['password'] = Hash::make($password);
}
public function save(array $options = array())
{
    $this->mdbid = $this->mdbid ?: str_random(16);

    $this->key  = $this->key  ?: str_random(11);

    parent::save($options);
}