While working with Laravel database query builder, there may be you need to grouping records with specific column.
For that, you may use the Laravel's groupBy()
method to group the record with specific column. But sometimes, even if your query is ok, still you get error in Laravel even if row query works perfect in MySQL command line.
Here is query example.
$posts = DB::table('posts')
->groupBy('views')
->get();
And the query returns with the bellow error.
After digging dipper about the error, I found the reason. It is due to the MySQL server version 5.7.5+. From this version on the way GROUP BY works is changed since they make it behave in order to be SQL99 compliant, whereas in previous versions it was not.
To overcome this error, either we have to do a full groupBy or change MySQL server configuration. Here is my simple solution.
In the config/database.php
file, change the 'strict' => true, to 'strict' => false, in 'connections' => 'mysql' array. This will change MySQL's strict mode to disable.
'connections' => [
...
'mysql' => [
'strict' => false
]
]
I hope this article will help you to understand the error and solving in your work. If you liked it, please do share with your friends.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Create Multilevel Nested Comment System in Laravel 7.x Example
Hey Artisan Hope you are doing well i...How to Add New Elements at the Beginning of an Array in JavaScript
Use the unshift() Method You can use...How to detect click inside iframe using JavaScript
Use the jQuery contents() method If y...jQuery sliding effect example
In this article, we will describe on sli...Add Lazy Loading in Your Website for Better Website Performance
Lazy loading is a web development techni...