我有一段代码,我在其中传递了一个碳排放日期,看起来像这样:
2017-08-18 22:53:50.031922并希望将其与某些记录的created_at时间戳进行比较。但是,这些记录似乎没有被过滤掉;where语句中的比较是否有效?
$test = Auth::user()->tests()->with([
'participants.testRecords' => function ($query) use ($latestCapture) {
$query->select('id', 'score', 'test_id', 'participant_id', 'capture_timestamp', 'score', 'created_at');
$query->where('test_records.created_at', '>', $latestCapture);
}])->findOrFail($id)->toArray();发布于 2017-08-19 03:55:08
如果$latestCapture是instancej Carbon,你应该在这里使用:
$latestCapture->toDateTimeString()以确保您传递了有效的日期字符串。
还有一件事-你应该确保created_at是用PHP而不是MySQL (这是Laravel的默认格式)填充的-如果不是这样,当你在PHP和MySQL中有不同的时区时,你可以期待时移。
https://stackoverflow.com/questions/45764011
复制相似问题