当前位置: 动力学知识库 > 问答 > 编程问答 >

laravel 4 - Mass assignment enter value in guarded field

问题描述:

Is it possible to fill a guarded field with the ::create method from Elequent models,

If my User model is like so:

$guarded=['password','id']

$fillable=['username']

Is it possible to do this?

User::create(['username'=>'mynewusername','password'=hash::make($password)])

网友答案:

No - you cannot do that.

But you could do this

$user = User::create(['username'=>'mynewusername']);
$user->password = Hash::make($password);
$user->save();
分享给朋友:
您可能感兴趣的文章:
随机阅读: