Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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
Laravel更新或创建时间戳更新问题_Laravel_Eloquent_Laravel 5.2 - Fatal编程技术网

Laravel更新或创建时间戳更新问题

Laravel更新或创建时间戳更新问题,laravel,eloquent,laravel-5.2,Laravel,Eloquent,Laravel 5.2,我正在使用updateOrCreate方法检查数据是否已从数据库中输入的响应中更改。如果记录是新的,则会成功添加正确的时间戳。然而,我注意到更新的时间戳更新了所有记录的记录。我只希望在记录已更新的情况下更新 但从这个问题来看,我相信所有的记录都在更新 if (isset($customers->Data)) { foreach ($customers as $customerData) { if ($customer = $customerData->attr

我正在使用updateOrCreate方法检查数据是否已从数据库中输入的响应中更改。如果记录是新的,则会成功添加正确的时间戳。然而,我注意到更新的时间戳更新了所有记录的记录。我只希望在记录已更新的情况下更新

但从这个问题来看,我相信所有的记录都在更新

if (isset($customers->Data)) {
    foreach ($customers as $customerData) {
        if ($customer = $customerData->attributes()) {
            if ((string) $customer->CustomerType !== 'A') continue;
            if ((string) $customer->CustomerEmail === '') continue;

            $customerDb = $this::updateOrCreate(
                [
                    'email'    => $customer->CustomerEmail,
                    'code'     => $customer->Customer,
                    'currency' => $customer->Currency,
                ],
                [
                    'email'    => $customer->CustomerEmail,
                    'code'     => $customer->Customer,
                    'currency' => $customer->Currency,
                    'name'     => $customer->CustomerName,
                    'phone'    => $customer->CustomerPhone,
                    'terms'    => $customer->Terms,
                ]
            );
        }
    }
}
电子邮件、代码、货币字段将始终是唯一的,如果不存在,则创建其余字段。默认行为是否应该是它无论如何都会更新?我想要实现的是,仅检测记录是否已更改,如果它已更新该特定字段,则更新时间戳(如果不存在),然后创建它。因此,过滤掉已更新的内容,只显示这些记录,而不是整个表


很抱歉,新来的拉威尔欢迎任何指导,谢谢

我想现在还不清楚你到底想要什么,至少对我来说,你能写一个输入和输出的例子吗?或者写一些东西来帮助理解它。updateOrCreate的默认行为是,如果找到了,总是更新模型。当你告诉拉威尔更新时,他怎么知道他不应该更新?您最好编写代码,搜索现有数据,在不存在数据时创建,否则检查数据是否更改,然后再保存模型。我认为您至少不清楚您到底想要什么,你能写一些输入和输出的例子吗?或者一些有助于理解它的东西。updateOrCreate的默认行为是在找到模型时总是更新模型。当你告诉拉威尔更新时,他怎么知道他不应该更新?您最好编写代码,搜索现有数据,在不存在数据时创建,否则检查数据是否更改,然后保存模型。