Krystian Polska Krystian Polska - 3 years ago 113
PHP Question

Laravel - Group By error on query that works on phpmyadmin with results

The query is:

$last_topics = Topics::orderby('date', 'DESC')->groupBy('section')->get();


And error:

enter image description here

so on error we can see query is:
select * from
topics
group by
section
order by
date
desc


But as you can see The same query in phpMyAdmin works great, and I have my result
enter image description here

So what's wrong?

I addition I can say that without groupBy in this query inside Laravel doesn't alert error, like:
$last_topics = Topics::orderby('date', 'DESC')->get();


But as I said in phpmyadmin the same query with groupby works great

Answer Source

OK this the mode in which your database is being used within your database config /config/database.php. Laravel is not adding all the columns to group by.

'connections' => [
        'mysql' => [
            // Will work for you
            'strict' => false,

            // wont work for you
            'strict' => true,
        ]
    ]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download