我在数据库连接设置中将strict设置为false,如下所示:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null
],
但在尝试在Eloquent查询中链接groupBy时,我仍然收到GROUP BY ALL错误消息。
SQLSTATE[42000]: Syntax error or access violation: 1055 'spinal.exercise_programs.id' isn't in GROUP BY (SQL: select * from `exercise_programs` where `client_id` = 1 group by `exercise_id`)
在这种情况下需要使用groupBy:
$exercises = ExerciseProgram::where('client_id', '=', $client)->groupBy('exercise_id')->get();
答案 0 :(得分:0)
在Laravel中更改任何配置后,您需要清除config
缓存。
$ php artisan config:clear