gpt4 book ai didi

php - laravel Eloquent 查询构建器在没有任何逻辑的情况下更新自定义时间戳字段

转载 作者:行者123 更新时间:2023-11-29 06:06:36 25 4
gpt4 key购买 nike

我在名为 expired(boolean)expire_date(timestamp) 的表中有两列。我正在运行一个调度程序来检查 everyMinute() 中的优惠券是否过期,同时使用 foreach 更新 expired 列值,我发现它更改了 expired_date 列今天日期的值(value)。我发现这很奇怪,或者可能是我弄乱了按引用传递的东西。这是代码

$schedule->call(function () {
CoursePromotion::where('expired',0)
->whereDate('expire_date','<',Carbon::today())
->update(['expired' => 1]);
})->everyMinute();

这是结果,

更新前的数据库

enter image description here

运行 php artisan schedule:run 命令后的数据库

enter image description here

谁能告诉我为什么 expired_date 已更新为今天的日期?

最佳答案

检查您的数据库表(具有此“expired_date”列),不确定但同一列的属性有问题。如果您在“expired_date”列中找到类似“on update CURRENT_TIMESTAMP”的属性,请将其删除并检查。

enter image description here

此外,此“on update CURRENT_TIMESTAMP”属性将在对特定记录执行更新操作时更新当前日期。

关于php - laravel Eloquent 查询构建器在没有任何逻辑的情况下更新自定义时间戳字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41159290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com