我编写了一个函数来根据日期过滤用户和代理商预订的票证。这基本上是一个票务预订申请。在此用户和代理可以预订不同的票证,因此在管理仪表板中,我显示用户今天预订的票数总数,反之亦然。因此,我使用Carbon来验证今天的日期。但我得到了不同的输出!
控制器:
$ticketsTodayUsers = Booking::with('users')->where("createdAt", ">=", Carbon::today())->whereHas("users", function($subQuery){
$subQuery->where("usertype", "=", "normal");
})->get();
所以在这里我有两个表,预订和用户表,我通过使用carbon :: today()和usertype作为普通代理或代理来验证今天创建的票证。
但是当我今天(19-sep-2018)检查时,我正在计算昨天的结果(18-sep-2018)。我没有得到今天的数,这是零而不是计数来自昨天或长期回来像14-sep-2018。我不知道我做错了什么!
主要条件是我需要将每天的用户和代理预订计数分开,因此通过使用db和carbon今天提交的createdAt函数我尝试匹配两者。但我没有得到预期的答案!
尝试使用$ tz参数 - TimeZone。
Carbon::today('Asia/Calcutta');
并尝试使用WhereData()
,WhereDay()
:
->whereDay('createdAt', '=', date('d'))
要么
->whereDate('createdAt', Carbon::today())
当然有适当的时区
Booking::with('users')->whereDate('createdAt', Carbon::today('Asia/Calcutta')->toDateString())->whereHas("users", function($subQuery){
$subQuery->where("usertype", "=", "normal");
})->get();
试试这个:
$ticketsTodayUsers = Booking::with('users')
->whereDate("createdAt", ">=", Carbon::now()->toDateString())
->whereHas("users", function($subQuery){
$subQuery->where("usertype", "=", "normal");
})->get();