LaravelTrust and LaravelAuthUI can't import role to database

124 Views Asked by At

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');
}
1

There are 1 best solutions below

0
On

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');