簡體   English   中英

Eloquent,更新update_at和當前時間的小時(時間)差大於24的所有記錄

[英]Eloquent, update all records where hours (time) difference between update_at and current time is greater than 24

我需要更新update_at當前時間相差大於 24 小時的所有記錄。 實際上,我僅在 24 小時內將業務更新為功能,之后業務將自動取消訂閱功能。 所以我想像這樣更新所有的業務。

 Business::where('is_featured', true)
        ->whereDate('updated_at', '<', now()) // need to calculate difference of 24 hours
        ->update(['is_featured' => false]);

使用碳,減去 24 小時

Business::where('is_featured', true)
    ->whereDate('updated_at', '<', now()->subHours(24))
    ->update(['is_featured' => false]);

或 subDay()

Business::where('is_featured', true)
    ->whereDate('updated_at', '<', now()->subDay())
    ->update(['is_featured' => false]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM