严格模式无效

时间:2018-01-23 07:24:34

标签: laravel eloquent

我在数据库连接设置中将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();

1 个答案:

答案 0 :(得分:0)

在Laravel中更改任何配置后,您需要清除config缓存。

$ php artisan config:clear