title: How to group attendance logs of a specific User - Eloquent
body: <p>i'm creating an attendance report module.</p>
  
  <p>i have two tables, one is <code>User</code> table and the other one is <code>attendance_log</code></p>
  
  <p>here's the column of each table</p>
  
  <p><code>Users</code> table</p>
  
  <p><code>---------------------------------
  |user_id | first_name | lastname|
  |    1   | jesse      | leech   |
  |    2   | howard     | jones   |</code></p>
  
  <p><code>attendance_log</code> table</p>
  
  <p><code>---------------------------------
  |log_id | user_id | status   | created_at          | updated_at          |
  |    1  | 1       | entrance | 2017-08-09 13:08:57 | 2017-08-09 13:08:57 |
  |    2  | 1       | entrance | 2017-08-09 13:09:00 | 2017-08-09 13:09:00 |
  |    3  | 1       | entrance | 2017-08-09 13:09:03 | 2017-08-09 13:09:03 |
  |    4  | 2       | entrance | 2017-08-09 13:10:28 | 2017-08-09 13:10:28 |
  |    5  | 2       | entrance | 2017-08-09 13:10:30 | 2017-08-09 13:10:30 |
  |    6  | 2       | entrance | 2017-08-09 13:10:31 | 2017-08-09 13:10:31 |
  |    7  | 1       | entrance | 2017-08-10 13:08:57 | 2017-08-10 13:08:57 |
  |    8  | 1       | entrance | 2017-08-10 13:09:00 | 2017-08-10 13:09:00 |
  |    9  | 1       | entrance | 2017-08-10 13:09:03 | 2017-08-10 13:09:03 |
  |    10 | 2       | entrance | 2017-08-10 13:10:28 | 2017-08-10 13:10:28 |
  |    11 | 2       | entrance | 2017-08-10 13:10:30 | 2017-08-10 13:10:30 |
  |    12 | 2       | entrance | 2017-08-10 13:10:31 | 2017-08-10 13:10:31 |</code></p>
  
  <p>as you can see to the <code>attendance_log</code> table, i have multiple <code>created_at</code> value, because im using rfid tapping for inserting data for the attendance.</p>
  
  <p>here's my problem, when i'm grouping it by <code>created_at</code> the result will be: </p>
  
  <p><code>-----------------------------------------------
  | first name | last name | date &amp; time         |
  | jesse      | leech     | 2017-08-09 13:08:57 |
  | jesse      | leech     | 2017-08-10 13:08:57 |</code></p>
  
  <p>instead of:</p>
  
  <p><code>-----------------------------------------------
  | first name | last name | date &amp; time         |
  | jesse      | leech     | 2017-08-09 13:08:57 |
  | jesse      | leech     | 2017-08-10 13:08:57 |
  | howard     | jones     | 2017-08-09 13:10:28 |
  | howard     | jones     | 2017-08-10 13:10:28 |</code></p>
  
  <p>how can i achieve this?</p>
  
  <p>here's my code</p>
  
  <pre><code>    $students = User::has('userStudentAttendance')-&gt;with(['userStudentAttendance' =&gt; function($query) use ($details,$search_from, $search_to){
      $query-&gt;where('status', $details);
      $query-&gt;where(function($query) use ($search_from, $search_to){
              $query-&gt;whereBetween(DB::raw('Date(created_at)'), [$search_from, $search_to]);
          });
      $query-&gt;groupby(DB::raw('Date(created_at)'));
      }])
      -&gt;leftjoin('sys_user_student', 'sys_user_student.user_id', '=', 'sys_user.user_id')
      -&gt;leftjoin('sys_mf_section', 'sys_mf_section.section_id', '=', 'sys_user_student.section_id')
      -&gt;leftjoin('sys_mf_grade', 'sys_mf_grade.grade_id', '=', 'sys_mf_section.grade_id')     
      -&gt;where('user_type_id', '4')
      -&gt;where('sys_mf_section.section_id', $request-&gt;getParam('section_id'))
      -&gt;where('sys_mf_grade.grade_id', $request-&gt;getParam('grade_id'))        
      -&gt;get();
  </code></pre>
  
  <p>hoping someone can help me and sorry for my poor english. Thank you guys!</p>