Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel firstOrNew覆盖所有条目_Php_Laravel_Laravel 5.2 - Fatal编程技术网

Php Laravel 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' =>

firstOrNew()方法有问题。请看下面我的方法

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