Php Laravel firstOrNew覆盖所有条目
firstOrNew()方法有问题。请看下面我的方法Php Laravel firstOrNew覆盖所有条目,php,laravel,laravel-5.2,Php,Laravel,Laravel 5.2,firstOrNew()方法有问题。请看下面我的方法 public function updateUnique($attributeId, $data) { $attribute = \App\Clients\Attribute::firstOrNew( [ 'mem_id' => $data->lead_id, 'attribute_id' => $attributeId, 'type' =>
public function updateUnique($attributeId, $data)
{
$attribute = \App\Clients\Attribute::firstOrNew(
[
'mem_id' => $data->lead_id,
'attribute_id' => $attributeId,
'type' => $this->updateType($data->pk)
] );
$attribute->mem_id = $data->lead_id;
$attribute->type = $this->updateType($data->pk);
$attribute->attribute_id = $attributeId;
$attribute->attribute = $data->value;
$attribute->save();
}
在我添加属性$primaryKey=“mem_id”之前,这一切都非常顺利模型属性上的代码>
如果为“第一个”,则更新数据库中的所有条目。“新”方面工作正常
只要我移除它,它就会工作。我想尝试了解发生了什么?如果您有
$primaryKey='mem_id'
并且它不是自动递增的,那么您还需要提供public$incrementing=false代码>也在你的属性模型上-@见感谢@ash我没意识到。但它并没有解决这个问题?那么您在属性的$filleble
属性中是否有mem\u id
?