mardi 26 avril 2016

Laravel 5.2 didn't mutate attribute when model "create" method used

I'm trying to implement "auto-encryption" for my model's password attribute, using mutator like this:

public function setPasswordAttribute($value)
{
    $this->attributes['password'] = Hash::make($value);
}

This works perfect when I'm creating and saving model like this:

$user = new User;
$user->login = 'WalterSobchak';
$user->password = 'MarkItZero!';
$user->save();

However, when i'm using create method:

User::create([ 'login' => 'WalterSobchak', 'password' => 'MarkItZero!' ]);

mutator didn't have effect and model is creating with plain password field.

I'm definitely missing something obvious, but really can't figure out whats wrong.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire