很抱歉我Zizaco/entrust在新用户注册时遇到问题,他没有角色,我需要成为客户Role。在里面 RegisterControllerprotected function create(array $data){ return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); $role = Role::where('name','client')->firstOrFail(); $user->attachRole($role); return $user; }
2 回答
富国沪深
TA贡献1790条经验 获得超9个赞
我用过这个,效果很好:
protected function create(array $data)
{
$userModel = new User();
$userModel->name = $data['name'];
$userModel->email = $data['email'];
$userModel->password = Hash::make($data['password']);
$userModel->save();
$role = Role::where('name', 'client')->first();
$userModel->roles()->attach($role->id);
return $userModel;
}
- 2 回答
- 0 关注
- 140 浏览
添加回答
举报
0/150
提交
取消