I am trying to assign multiple role while creating a user programatically. I am successfully creating a user and assigning one role using below code
$user = \Drupal\user\Entity\User::create(); // Mandatory. $user->setPassword('111'); $user->enforceIsNew(); $user->setEmail('email@example.com'); $user->setUsername('abcd'); $user->addRole('lecturer'); $user->save();
I want to assign two roles during this code execution and tried the below code but it did not work
How do I assign this?