Search code examples
laravellaravel-5laravel-5.3

Group by Laravel?


I have the following query:

$orders = Order::where(function ($query) use ($request) {

            // Filter by in process delivery
            if ($request->get("status") && $request->get("status") == "2") {
                $query->where('status', "2");
            }

        })->groupBy('created_at')->get();

When I try to execute this query I get an error:

SQLSTATE[42000]: Syntax error or access violation: 1055 'delivery.order.id' isn't in GROUP BY (SQL: select * from `order` group by `created_at`)

What is problem?


Solution

  • In your config/database.php file, change mysql configuration array

    from 'strict' => true

    to 'strict' => false

    For more information about this error read this answer.