gpt4 book ai didi

php - 在 Laravel 中检索 updated_at 比 created_at 早 2 小时的记录( Eloquent )

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

我想计算 updated_at 比 created_at 早 2 小时的记录。

代码

$teLang = $kentekens->where('updated_at', '>', 'created_at'->subHours(2));

不幸的是,这不起作用,因为 subHours(2) 用于碳,但希望您明白了。

查看

<h1>{{ $teLang->count() }}</h1>

Controller

public function create() {
$kentekens = Kenteken::latest()
->where('created_at', '>=', Carbon::today())
->get();

$teLang = $kentekens->where('updated_at', '>', 'created_at'->subHours(2));

return view('layouts.dashboard', compact('kentekens', 'teLang'));
}

有人知道吗?

最佳答案

$kentekens->whereRaw('`updated_at` > DATE_ADD(`created_at`, INTERVAL 2 HOUR)');

SQL:

select `id` from `tablename` where `updated_at` > DATE_ADD(`created_at`, INTERVAL 2 HOUR)

关于php - 在 Laravel 中检索 updated_at 比 created_at 早 2 小时的记录( Eloquent ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48409110/

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