How to disable only_full_group_by option in Laravel



PHP Snippet 1:

SELECT a1.*
FROM A a1
INNER JOIN
(
    SELECT A.id
    FROM A
    INNER JOIN B
        ON A.id = B.a_id 
    INNER JOIN C
        ON C.id = B.c_id
    GROUP BY A.id
    HAVING COUNT(A.id) > 0
) a2
    ON a1.id = a2.id;

PHP Snippet 2:

'connections' => [
...

    'mysql' => [
    ...
        'strict' => false,
        ...

    ],

]

PHP Snippet 3:

//disable ONLY_FULL_GROUP_BY
DB::statement("SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");

//Your SQL goes here - The one throwing the error (:

//re-enable ONLY_FULL_GROUP_BY
DB::statement("SET sql_mode=(SELECT CONCAT(@@sql_mode, ',ONLY_FULL_GROUP_BY'));");

PHP Snippet 4:

'mysql' => [
 ...
        'modes' => [
            'STRICT_ALL_TABLES',
        ],
],