This error is not because of the Laravel actually. This is MySQL error and which comes if you have ONLY_FULL_GROUP_BY inside the SQL_MODE variable in your DB.
Of course you can handle it at MySQL level by removing ONLY_FULL_GROUP_BY from you SQL_MODE.
But Laravel also provides the functionality to handle this error.
check your config/database.php And check if inside the mysql settings there is one that is like:
1
|
'strict' => true,
|
If you turn 'strict' to false will resolve you issue like;
1
|
'strict' => false,
|
But if you are turning 'strict' to false will remove all these below SQL modes.
1) ONLY_FULL_GROUP_BY
2) STRICT_TRANS_TABLES
3) NO_ZERO_IN_DATE
4) NO_ZERO_DATE
5) ERROR_FOR_DIVISION_BY_ZERO
6) NO_AUTO_CREATE_USER
7) NO_ENGINE_SUBSTITUTION
And the issue we are facing is just because of ONLY_FULL_GROUP_BY SQL_MODE.
So I think turning off all the SQL_MODES is not a better approach yaah it can be quick fix.
Laravel provides a beautiful feature and that is we also can define our SQL modes with every database connection in out configuration file.
Like if we need 2 SQL_MODE then we can define it like:
1
2
3
4
|
'modes' => [
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ZERO_IN_DATE',
],
|
So we can set the SQL_MODE in our configuration file 'config/database.php' like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
'mysql' => [
'driver' => 'mysql',
'host' => 'HOST_NAME',
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'DB_NAME'),
'username' => 'USER_NAME',
'password' => 'PASSWORD',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'modes' => [
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_AUTO_CREATE_USER',
'NO_ENGINE_SUBSTITUTION'
],
]
|
So here I just removed ONLY_FULL_GROUP_BY SQL_MODE from the modes list which will also resolve the access violation of group By.
And I will keep:
1
|
'strict' => true,
|
Good Explanation.. Greate Post Bro....