Eloquent:从时间戳中仅获取日期

3
我想获取某个用户某天的所有记录,但我不知道如何格式化查询。
public function getEntry()
{
    $entries = Journal::where('id', '=', Auth::id())
    ->where('created_at', '=', '\Carbon\Carbon::now()->format("l j F Y")')
    ->get()->first();
    return view('home')->with(compact('entries'));
}

我不知道如何格式化'created_at'以匹配服务器时间。希望能得到帮助,非常感谢。

1个回答

3
使用 whereDate() 来获取指定日期的所有条目:
->whereDate('created_at', Carbon::today());

或者使用 whereBetween()

->whereBetween('created_at', [Carbon::now()->startOfDay(), Carbon::now()->endOfDay()])

或者使用简单的 where() 方法:

->where('created_at', '>', Carbon::now()->startOfDay())
->where('created_at', '<', Carbon::now()->endOfDay())

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接