2017-06-05 70 views
2

我想获取用户的特定日期的所有条目..我不知道如何格式化查询。Eloquent:只获得时间戳的日期

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'以匹配服务器时间。任何帮助将主要赞赏。谢谢。

回答

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())