Reputation: 1
I have a problem with LaraTrust $User->attachRole('user')
, and Laravel Auth UI. I want to attach a role upon registering a new User. After the registering, I don't see any data in the roles table.
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'phonenumber' => $data['phonenumber'],
'password' => Hash::make($data['password']),
]);
$User->attachRole('user');
}
Upvotes: 0
Views: 124
Reputation: 2480
You are directly returning the created user before attaching the role.
Either:
$user = User::create([]);
$user->attachRole('user');
return $user;
Or
return User::create([])->attachRole('user');
Upvotes: 0