title: Laravel 4 - Datatables - Call to a member function getQuery() on array
body: <p>The following query MySQL works correctly in MySQL MyAdmin.</p>
  
  <pre><code>SELECT contacts.id, contacts.gsm, contacts.name, contacts.last_name, contacts.email, contacts.created_at,  if(temp.Count &gt;= 1,temp.Count,0) as newCount
          FROM contacts
          LEFT JOIN
          (SELECT contacts.id, COUNT(groupcontact.id) AS Count
          FROM contacts
          LEFT JOIN groupcontact ON groupcontact.contacts_id = contacts.id
          LEFT JOIN groups ON groups.id = groupcontact.groups_id
          WHERE groups.id = :idGrupo
          GROUP BY contacts.id)
          temp ON temp.id = contacts.id
  </code></pre>
  
  <p>BUT when i try to run with LARAVEL + Datatables in RAW DB, returns this error-
  {"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Call to a member function getQuery() on array","file":"C:\xampp\htdocs\mcdigital\laravel\vendor\bllim\datatables\src\Bllim\Datatables\Datatables.php","line":256}}</p>
  
  <p>I dont know why  </p>
  
  <hr>
  
  <p>LARAVEL controller</p>
  
  <pre><code>$sql="SELECT contacts.id, contacts.gsm, contacts.name, contacts.last_name, contacts.email, contacts.created_at,  if(temp.Count &gt;= 1,temp.Count,0) as newCount
              FROM contacts
              LEFT JOIN
              (SELECT contacts.id, COUNT(groupcontact.id) AS Count
              FROM contacts
              LEFT JOIN groupcontact ON groupcontact.contacts_id = contacts.id
              LEFT JOIN groups ON groups.id = groupcontact.groups_id
              WHERE groups.id = :idGrupo
              GROUP BY contacts.id)
              temp ON temp.id = contacts.id";
      $usuarios = DB::select( DB::raw($sql), array('idGrupo' =&gt; $idGrupo));
  
      return Datatables::of($usuarios)
      -&gt;add_column('options', '
                      &lt;label class="toggle yesNoGroup pull-left"&gt;
                        &lt;input type="checkbox" name="checkbox-toggle" id="yesNoGroupchk-{{ $id }}" @if(newCount &gt;0)checked@endif&gt;
                        &lt;i&gt;&lt;/i&gt;&lt;/label&gt;
                      ')-&gt;make(); 
  </code></pre>
  
  <p>JS Datatables</p>
  
  <pre><code>if ($(tablaName).length &amp;&amp; !isNaN(idGroup)) {
          var $oTable = $(tablaName).dataTable({
              "bServerSide": true,
              "sAjaxSource": '/contact-list-group-load/'+idGroup,
              "autoWidth": true,
              "oLanguage": {
                  "sProcessing":     '&lt;image src="/images/ajax-loader.gif" alt="Cargando..."&gt;',
                  "sLengthMenu":     "Mostrar _MENU_ contactos",
                  "sSearch":         "Buscar:",
                  "sZeroRecords":    "No se encontraron resultados",
                  "sInfo":           "Mostrando _START_ al _END_ de un total de _TOTAL_ contactos",
                  "oPaginate": {
                      "sFirst":    "Primero",
                      "sLast":     "Último",
                      "sNext":     "Siguiente",
                      "sPrevious": "Anterior"
                  }
              },
              "aaSorting": [[0, 'desc']],
              "sDom":
                      "&lt;'row'&lt;'col-xs-6'l&gt;&lt;'col-xs-6'f&gt;r&gt;"+
                      "t"+
                      "&lt;'row'&lt;'col-xs-12 text-center tableCuantosRegistros'i&gt;&lt;'col-xs-12 text-center'p&gt;&gt;",
              "sLoadingRecords": '&lt;image src="/images/ajax-loader.gif" alt="Cargando..."&gt;',
              "aoColumnDefs": [
                  { "bSearchable": false, "aTargets": [ 5, 6 ] },
                  { "bSortable": false, "aTargets": [ 5, 6 ] }
                ],
              "fnDrawCallback": function (oSettings) {
  
             },
              "iDisplayLength": 100
       });
  </code></pre>
  
  <p>Maybe, just to ask how to convert this mysql query to Laravel Eloquent or Laravel Query Builder. Please advise. </p>
  
  <p>THANKS IN ADVANCE</p>