2017-06-20 86 views
0

這是我的查詢,它適用於所有舊版本。Laravel groupBy not working,version 5.4.24

$data = DB::table('applicant') 
      ->groupBy('AppAffID') 
      ->get(); 

的錯誤,我得到的是:

SQLSTATE[42000]: Syntax error or access violation: 1055 'comloant_loantreeAPI.applicant.AppID' isn't in GROUP BY (SQL: select * from `applicant` group by `AppAffID`) 

我已經試過了數據庫的變化:

我說 '嚴'=>假,數據庫配置。

'mysql' => [ 
      'driver' => 'mysql', 
      'host' => env('DB_HOST', 'localhost'), 
      'port' => env('DB_PORT', '3306'), 
      'database' => env('DB_DATABASE', 'forge'), 
      'username' => env('DB_USERNAME', 'forge'), 
      'password' => env('DB_PASSWORD', ''), 
      'charset' => 'utf8', 
      'collation' => 'utf8_unicode_ci', 
      'prefix' => '', 
      'strict' => false, 
      'engine' => null, 
     ], 
+0

你能告訴數據庫配置文件? – Teun

+0

@Teun,我加了 – ALCHI

+0

你確定你使用的是mysql嗎?更改配置後,你清除了配置緩存? 'php artisan config:clear' – Teun

回答

0

你想用groupBy實現什麼?如果要排序的AppAffID你應該使用orderBy像這樣做,而不是:

$data = DB::table('applicant') 
     ->orderBy('AppAffID', 'desc') //can also use 'asc' for ascending 
     ->get(); 
+0

如果我使用sortBy我得到一個錯誤:BadMethodCallException調用未定義的方法Illuminate \ Database \ Query \ Builder :: sortBy() – ALCHI

+0

已更新的答案,我的意思是'orderBy' – Teun