Laravel query works with database.php strict=false. How to make it work with strict=true?
GROUP BY
statements in strict mode require that all the non-aggregate fields (COUNT
, SUM
, MAX
, etc.) in the SELECT
statement be present in the GROUP BY
.
As shown in the error, the whereHas()
method has produced a select *
query, however, your GROUP BY
statement only has transaction_id
.
To fix this, you can simply add select('transaction_id')
to your whereHas
call:
->whereHas("allocations", function ($query) {
$query->select('transaction_id')
->havingRaw('transactions.credit > sum(amount)')
->groupBy('transaction_id');
})
Strict mode not working
You need to clear the config
cache after you change any configuration in Laravel.
$ php artisan config:clear
Laravel error when get data from mySQL using groupBy
This is caused by MySQL's strict mode. Change strict
to false in your config/database.php
file.
When you open the file, in the mysql
array, set strict => false
. After you disable MySQL's strict mode it shouldn't show the error anymore.
Related Topics
PHP Replace All Spaces with Hyphens
How to Start Local Server with Symfony 5 or Downgrade Version to 4.4
How to Get Average of Column Values in Laravel
Laravel 5 Carbon Global Locale
Redirect to New Page W/ Post Data (Php/Zend)
MySQL Password Hashing Method Old VS New
Php:Difference Between '&&' and 'And'
Namevaluepair Error "Namevaluepair Cannot Be Resolved to a Type"
How to Run from PHP a Bash Script Under Root User
Set Quantity Minimum, Maximum and Step at Product Level in Woocommerce
PHP File_Get_Contents() Behaves Differently to Browser
Extension PHP5 Does Not Parse in Xampp
Warning: MySQLi_Connect(): Unknown MySQL Server Host
Implementing Oauth2 Login, Fatal Error: Class 'Google_Service' Not Found