如何根据 Carbon 日期查询 MongoDB?
How can I query MongoDB based on Carbon dates?
这是我希望 return 一个结果的代码片段:
$today = new Carbon();
$newUser = new User();
$newUser->yesterday = $today->subDay();
$newUser->save();
$matches = User::where('yesterday', '<', $today)->get();
return $matches;
然而我得到一个空数组。有人可以帮我找出这里的问题吗?
我相信这与我保存 yesterday
属性 的方式有关。如果它是 ISODate,则此查询将正常工作。也许我在将 Carbon 对象转换为 ISODates 时遗漏了一些明显的东西...
感谢任何帮助。
我建议在适当的 laravel 模型(与碳配合得非常好)上使用日期 属性
class User extends Model
{
protected $dates = ['yesterday'];
public function yourfunction(){
}
}
laravel 文档对如何使用日期有很好的指导 属性 here
这是我希望 return 一个结果的代码片段:
$today = new Carbon();
$newUser = new User();
$newUser->yesterday = $today->subDay();
$newUser->save();
$matches = User::where('yesterday', '<', $today)->get();
return $matches;
然而我得到一个空数组。有人可以帮我找出这里的问题吗?
我相信这与我保存 yesterday
属性 的方式有关。如果它是 ISODate,则此查询将正常工作。也许我在将 Carbon 对象转换为 ISODates 时遗漏了一些明显的东西...
感谢任何帮助。
我建议在适当的 laravel 模型(与碳配合得非常好)上使用日期 属性
class User extends Model
{
protected $dates = ['yesterday'];
public function yourfunction(){
}
}
laravel 文档对如何使用日期有很好的指导 属性 here