只返回10个没有设置LIMIT的值?

时间:2018-03-28 02:21:51

标签: php arrays laravel date eloquent

我做了一个功能,用户将从"中选择一个"和"到"日期,它将返回用户选择的日期的值,并且它将计算当天的不同用户,并且它还将计算相同的日期。所以它会返回正确的东西 enter image description here

但我现在面临的问题是它只返回最多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();
}




数据库表结构
enter image description here

1 个答案:

答案 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;