1

是否可以使用 Elequent 模型中的 ::create 方法填充受保护的字段,
如果我的用户模型是这样的:

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

是否有可能做到这一点?

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

1 回答 1

1

不——你不能那样做。

但你可以这样做

$user = User::create(['username'=>'mynewusername']);
$user->password = Hash::make($password);
$user->save();
于 2014-10-05T05:39:25.957 回答