I'm trying to learn Laravel and I'm checking some ACL's along the way. Currently I'm testing Entrust/Zizaco and I'm trying to add default role when user is registered.
I've added this to the create function in RegisterController.php
$user = User::find($create->id);
$role = Role::where('name', '=', 'customers')->firstOrFail();
$user->roles()->attachRole($role->id);
This is full function
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$user = User::find($create->id);
$role = Role::where('name', '=', 'customers')->firstOrFail();
$user->roles()->attachRole($role->id);
return $user;
}
The problem is that the user is created but the role isn't assigned. No errors also. Can anyone help me a bit here?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire