Answer the question
In order to leave comments, you need to log in
Why is the password not correct with this method of creating a user?
Good afternoon, I need to register such a user when filling in the data in the form, there are no problems with this, but I had a problem that if I create a user in this way:
$pass = Str::random(10);
$user['company_id'] = $company->id;
$user['name'] = $company->contact;
$user['surname'] = 'Admin';
$user['phone'] = $company->phone;
$user['email'] = $company->email;
$user['password'] = bcrypt($pass);
$item = new User($user);
$item->save();
$pass = Str::random(10);
User::insert([
'company_id' => $company->id,
'name' => $company->contact,
'surname' => 'Admin',
'email' => $company->email,
'phone' => $company->phone,
'password' => bcrypt($pass),
]);
Answer the question
In order to leave comments, you need to log in
The second method inserts the value directly into the database, bypassing Eloquent.
And this means that the problem is in the double hashing of the password - first you pass the hashed value to the attribute, and somewhere inside the model there is also a setter that re-hashes what was passed. Such a setter was in the old versions out of the box, in the new ones it was removed (or vice versa, I don’t remember).
I do not recommend using the second method, since you lose half of the framework's capabilities in this way, it's better to deal with the first one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question