How can I solve incompatible with sql_mode=only_full_group_by in laravel eloquent?

前端 未结 12 1696
不思量自难忘°
不思量自难忘° 2020-11-29 11:09

My laravel eloquent is like this :

$products = Product::where(\'status\', 1)
            ->where(\'stock\', \'>\', 0)
            ->where(\'category         


        
12条回答
  •  迷失自我
    2020-11-29 11:46

    As said, set strict mode to false may give security bugs, what i am doing is to set sql_mode to empty before queries that require it. Note that it is a TEMPORARY change, once your connection is close (by laravel request) you will be set to original sql_mode=only_full_group_by (or beyond).

    DB::statement("SET sql_mode = '' ");

    Cheers, happy coding...

    ps.: its not laravel fault, if you try to execute this query directly on your DB you will face same result. This work around works in mysql as well as first statement and again, will be a temporary session change, not permanent.

提交回复
热议问题