Model::create() method considers only the original request value when creating a record
I am trying to create a record by passing the request object as an array like
User::create($request->toArray());
This works fine and the record is created in the table.
But I need to manipulate a field before creating the record,
$request->password = bcrypt($request->password);
//echo $request->password;
User::create($request->toArray());
This does not work and the record created in the table still has the old unencrypted value.
I can confirm that $request->password
does have the encrypted value. There seems to be something going on in $request->toArray()
call.
What am I missing here?
from Laravel Questions and Answers https://laravelquestions.com/laravel/modelcreate-method-considers-only-the-original-request-value-when-creating-a-record/
via Lzo Media
No comments:
Post a Comment