我通过Rainlabs定制了用户插件。
用户模型与用户组有关系。创建用户后,我要设置他的用户组(来宾,已注册等)。
它不起作用:
// also tried beforeCreate
public function afterCreate()
{
if (something)
// groups is a relation field name
$this->groups = 'guest'; // guest is a user group code
else
$this->groups = 'registered';
}
答案 0 :(得分:0)
解决方案:
// User model
public function afterCreate() {
$this->groups()->add(UserGroup::where('code', 'registered')->first());
...
}