我做了一个功能,用户将从"中选择一个"和"到"日期,它将返回用户选择的日期的值,并且它将计算当天的不同用户,并且它还将计算相同的日期。所以它会返回正确的东西
但我现在面临的问题是它只返回最多10个值,而不是更多。所以,如果我选择1/3/2018 - 15/3/2018,它只会从1/3/2018返回到10/3/2018。为什么会这样?
我的代码如下:
public function viewUniqueVisitorByDate(Request $request, $companyID)
{
$companyID = $this->decode($companyID);
$allUsers = DiraChatLog::whereBetween('date_access', [$request->from, $request->to])->orderBy('date_access', 'asc')->get();
foreach ($allUsers as $key => $users) {
$dates = strtotime($users->date_access);
$newformat = date('Y-m-d',$dates);
$userDates[$newformat] = $this->getUsers($newformat,$users);
}
dd($userDates);
$user = array_values($userDates);
$dates = array_keys($userDates);
// dd($user, $dates);
$from = $request->from;
$to = $request->to;
// dd($from, $to);
$companyID = $this->encodeID($companyID);
return view('AltHr.Chatbot.viewUniqueVisitor', compact('companyID','from','to', 'dates'))->with('user',json_encode($user,JSON_NUMERIC_CHECK))->with('dates',json_encode($dates,JSON_NUMERIC_CHECK));
}

private function getUsers($date,$users)
{
$userDates = Carbon::parse($date)->addDay()->toDateTimeString();
// dd($userDates,$date);
$noOfUsers = DiraChatLog::whereBetween('date_access', [$date,$userDates])->get();
// dd($noOfUsers);
return $noOfUsers->groupBy('user_id')->count();
}

答案 0 :(得分:1)
如果$request->from
和$request->to
不是日期时间格式。在每个where子句中,都应该是。
DiraChatLog::whereBetween(DB::raw('DATE(date_access)'), [$request->from, $request->to])
->orderBy('date_access', 'asc')->get();
$noOfUsers = DiraChatLog::whereBetween(DB::raw('DATE(date_access)'), [$date,$userDates])->get();
因为date_access
是日期时间格式。
不要忘记声明使用DB;