简体   繁体   English

updateOrCreate日期大于今天

[英]updateOrCreate where date is greater than today

Is there a way to updateorcreate records in a table where the created_at date field is greater than today(midnight)? 有没有办法在created_at日期字段大于今天(午夜)的表中更新或创建记录?

I have the following sample: 我有以下样本:

Model::updateOrCreate(
          [
            'match_id' => $match->id,
            // 'created_at' => some query here to match a record created today
          ]
        );

Here's the solution I found to work: 这是我发现的解决方案:

Model::updateOrCreate(
          [
            'match_id' => $match->id,
            'created_at' => Model::where('created_at', '>', DB::raw('CURDATE()'))->first()->created_at ?? null
          ],
          [
            'otherColumn' => $value
          ]
        );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM