title: Laravel group by, with relationship in different tables
body: <p>I am using laravel eloquent, trying to fetch information contained in different tables and compare them.</p>
  
  <p>My tables are</p>
  
  <pre><code>tbl_checks
      id,check_id, person_id //person_id is the foreign key
  
  tbl_persons
     id, category, 
  </code></pre>
  
  <p>I would like to fetch all people in table <code>tbl_checks</code> and group the data by person category <code>tbl_persons.category</code>.</p>
  
  <p>In normal SQL statement it's like:</p>
  
  <pre><code>select from tbl_checks group by tbl_person.category where the tbl_persons.id is contained in tbl_checks.person_id
  </code></pre>
  
  <p>In my models I have:</p>
  
  <pre><code>class PersonsModel extends Model {
      //connect to the next database
      protected $connection = 'inspection';
      protected $table = 'tbl_trucks';
  
      //relation with tbl_checks
  
      public function checks(){
          return $this-&gt;hasMany('App\TblChecks','person_id','id');
      }
  }
  </code></pre>
  
  <p>How can I use the ELoquent model, and not the Db facade?
  To make it abit clear.
  Am trying to find all persons who are in the table_checks and ignore persons id who are not in tbl_checks</p>