1 回答

TA貢獻1860條經驗 獲得超9個贊
未檢索到第一個用戶,因為碳實例created_at不匹配date('d') 更改您的代碼以使用today()幫助程序
$most_purchased_day = (int)Data::select('type')
->whereDate('created_at', '=', today())
->groupBy('type')
->orderByRaw('COUNT(*) DESC')
->first()->network_id;
假設今天創建了一個 Eloquent 模型
App\Data {
id: 1,
created_at: "2019-09-22 13:15:19",
updated_at: "2019-09-22 13:15:19",
}
date('d') 只返回一個整數,即當月 (22) 的天數,不能匹配2019-09-22 13:15:19見PHP:date
如果您想獲取在任何一天創建的記錄,即當天的編號,而不管月份和年份
使用whereDay
$most_purchased_day = (int)Data::select('type')
->whereDay('created_at', '=', date('d'))
->groupBy('type')
->orderByRaw('COUNT(*) DESC')
->first()->network_id;
來自Laravel 文檔
whereDate / whereMonth / whereDay / whereYear / whereTime
該whereDay方法可用于將列的值與一個月中的特定日期進行比較:
$users = DB::table('users')
->whereDay('created_at', '31')
->get();
- 1 回答
- 0 關注
- 144 瀏覽
添加回答
舉報