I am trying to create a set of bogus users, using random string names, which I will later use the IDs for. I am running into an error where it isn't recognizing some of the variables I pass through. Below is my code:
$password = bcrypt($this->generateRandomString(15));
$user = User::firstOrNew([
'email' => ($firstName . '@company.com'),
'password' => $password,
'username' => $username,
'firstname' => $firstName,
'lastname' => $lastName,
$userIds = $user->id;
SQLSTATE: Integrity constraint violation: 1062 Duplicate entry 'Ollie@positivelearning.com' for key 'users_email_unique' (SQL: insert into
`users` (`email`, `password`, `username`, `updated_at`, `created_at`) values (Ollie@positivelearning.com, y$rx8R0N5dVAibjpXxV0OF4uGGb7lradsl2xME
20ymMvv2YPaUWv3oq, olliepritsak, 2016-07-14 18:10:10, 2016-07-14 18:10:10))
SQLSTATE: Integrity constraint violation: 1062 Duplicate entry '' for key 'users_username_unique'
Okay, so based on the error (your original error posted)...doesn't look like you're passing the following values,
'username' => $username, 'firstname' => $firstName, 'lastname' => $lastName,...
Make sure in your
User model, you have these under
fillable, like so:
protected $fillable = [ ... 'username', 'firstname', 'lastname', ];
I think this is where your problem is stemming from.