msonowal msonowal - 1 year ago 119
PHP Question

Group by not working after upgrading to laravel 5.3

This is the code that was working on laravel 5.2

$menus = CmsMenuItem::groupBy('menu_id')->get();

but now it throws error

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1
of SELECT list is not in GROUP BY clause and contains nonaggregated
column '' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by (SQL: select * from 'cms_menu_items' group
by 'menu_id')

I have also tried

`strict => false`

in database.php but no effect

Nil Nil
Answer Source

Try this for database config.

 '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,

and use query like this way

$menus =DB::table('cms_menu_item')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download