我想查看我 30 分钟前提交的哪个订单。我正在使用 Carbon 包来检查这项工作。所以我使用了这段代码,但 Laravel 出现了这个错误: DateTime::__construct(): Failed to parse time string (created_at) at position 0 (c): The timezone could not be found in the database$now = carbon::now(); $orders= Order::where(Carbon::parse('created_at')->addMinutes(30) ,'>=' , h)->get(); foreach($orders as $order){ if (is_null($orders)){ return 'false'; }else{ return 'true'; } }事实上,我不确定我的代码,但如果where(Carbon::parse('created_at')不正确,什么是正确的代码?
1 回答

繁华开满天机
TA贡献1816条经验 获得超4个赞
该parse
函数需要一个字符串 date 将其解析为 Carbon 对象,而不是列名。
所以你应该把你的支票改成这样:
$orders = Order::where('created_at' ,'>=', now()->subMinutes(30))->get();
我now()
在 Laravel 中使用了辅助函数,它等于Carbon::now()
- 1 回答
- 0 关注
- 216 浏览
添加回答
举报
0/150
提交
取消