What Is the Use of Strict in Laravel Config/Database

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



Leave a reply



Submit