Q:

Count number of row using mysql query in laravel

I trying to use Laravel count() function to get the count of row. I have below code to count the number of row of 2 join table. 
Example 1: 
$row = DB::table('log_user_login')
                ->select(DB::raw('log_user_login.Password as LogPassword'), 'user.*')
                ->join('user', 'log_user_login.Username', '=', 'user.Username')
                ->where('log_user_login.LoginSession', '!=', '')
                ->groupBy('user.ID')
                ->get();
$count = sizeof($row);

Example 2: 
$count = DB::table('log_user_login')
            ->select(DB::raw('log_user_login.Password as LogPassword'), 'user.*')
            ->join('user', 'log_user_login.Username', '=', 'user.Username')
            ->where('log_user_login.LoginSession', '!=', '')
            ->groupBy('user.ID')
            ->count();

When I echo $count form Example 1, the number of $count is 15415. But $count of Example 2 return me 89. May I know why this happen and how can I get the number of row without using the get()?

A:

Example 1 displays the sizeof array in bytes, but example 2 displays total count returned by table. 
So, best way to get total count is using ->count() as done in example 2.
Hope you got your answer.

