title: Eloquent groupBy make "SQLSTATE[42000]" with valid SQL query in Laravel 5.3
body: <p>I have a strange problem with Eloquent which I'm trying to do the following:</p>
  
  <pre><code>$this-&gt;node = \DB::table('permission')
                  -&gt;select('permission.id',
                           'object.name as object_name',
                           'permission.created_at',
                           'object.id as object_id')
                  -&gt;join('object', 'object.id', '=', 'permission.object_id')
                  -&gt;join('action', 'action.id', '=', 'permission.action_id')
                  -&gt;where('permission.person_id', $this-&gt;person['id'])
                  -&gt;groupBy('permission.object_id')
                  -&gt;orderBy('permission.created_at', 'desc')
                  -&gt;paginate(5);
  </code></pre>
  
  <p><strong>Laravel Framework</strong> report an Error:</p>
  
  <blockquote>
    <p>QueryException in Connection.php line 761: SQLSTATE[42000]: Syntax
    error or access violation: 1055 'permission.id' isn't in GROUP
    BY (SQL: select <code>permission</code>.<code>id</code>, <code>object</code>.<code>name</code> as <code>object_name</code>,
    <code>permission</code>.<code>created_at</code>, <code>object</code>.<code>id</code> as <code>object_id</code> from
    <code>permission</code> inner join <code>object</code> on <code>object</code>.<code>id</code> =
    <code>permission</code>.<code>object_id</code> inner join <code>action</code> on <code>action</code>.<code>id</code> =
    <code>permission</code>.<code>action_id</code> where <code>permission</code>.<code>person_id</code> = 1 group by
    <code>permission</code>.<code>object_id</code> order by <code>permission</code>.<code>created_at</code> desc limit
    5 offset 0)</p>
  </blockquote>
  
  <p>I've added an Eloquent debugging function <strong>DB::listen</strong> in <em>AppServiceProvider</em>:</p>
  
  <pre><code>use Illuminate\Support\Facades\DB;
  use Illuminate\Support\ServiceProvider;
  
  class AppServiceProvider extends ServiceProvider
  {
      /**
       * Bootstrap any application services.
       *
       * @return void
       */
      public function boot()
      {
          //
           DB::listen(function ($query) {
  
              echo "&lt;pre&gt;";
              print_r($query-&gt;sql);
              echo "&lt;/pre&gt;";
  
              // $query-&gt;sql
              // $query-&gt;bindings
              // $query-&gt;time
          });
      }
      ...
  </code></pre>
  
  <p>And it does print this SQL query:</p>
  
  <pre><code>select  `permission`.`id`, 
          `object`.`name` as `object_name`, 
          `permission`.`created_at`, 
          `object`.`id` as `object_id` 
  from `permission` 
  inner join `object` on `object`.`id` = `permission`.`object_id` 
  inner join `action` on `action`.`id` = `permission`.`action_id` 
  where `permission`.`person_id` = 1 
  group by `permission`.`object_id` 
  order by `permission`.`created_at` desc 
  limit 5 offset 0
  </code></pre>
  
  <p>Which is valid in <em>MySQL</em> through <strong>PhpMyAdmin</strong> and here is the output for the query:
  <a href="https://i.stack.imgur.com/U0Mvf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U0Mvf.png" alt="SQL Query Output"></a>
  Even So, I tested in <code>mysql</code> command directly and it does work just fine, look at <em>mysql output</em>:</p>
  
  <p><a href="https://i.stack.imgur.com/8tJV3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8tJV3.png" alt="enter image description here"></a></p>
  
  <p>Any idea?</p>
  
  <p>Thanks</p>