[英]Laravel Eloquent
When I try to fill my database using the model method create
like this:当我尝试使用模型方法
create
我的数据库时,如下所示:
public function registerDevice($command) {
$deviceId = $command->deviceId;
$deviceToken = $command->deviceToken;
$this->deviceId = $deviceId;
$this->deviceToken = $deviceToken;
Device::create(array('device_id' => $deviceId, 'device_token' => $deviceToken));
$this->raise(new DeviceWasRegistered($this));
return $this;
}
The entry is being made, but only the timestamps are being updates.正在输入条目,但只有时间戳正在更新。 The value fields are empty.
值字段为空。 No error coming up or something else is failing.
没有出现错误或其他事情失败。 But the values I want to put into the db are there if I var_dump the variables.
但是如果我 var_dump 变量,我想放入数据库的值就在那里。
Do I miss something out?我错过了什么吗?
In order for the create method to work, you need to put your two fields in the $fillable
array on the model.为了使 create 方法起作用,您需要将两个字段放在模型的
$fillable
数组中。 So make sure you have this in your model:所以确保你的模型中有这个:
protected $fillable = [
'device_id',
'device_token',
];
You can read more about the create
method and mass assignment at http://laravel.com/docs/5.1/eloquent#mass-assignment .您可以在http://laravel.com/docs/5.1/eloquent#mass-assignment阅读有关
create
方法和质量分配的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.