1

Knowing that I made it strict             
this is my problem;

SQLSTATE[42000]: Syntax error or access violation: 1055 'auth.orders.created_at' isn't in GROUP BY (SQL: select YEAR(created_at) as year, MONTH(created_at) as month, SUM(item_count) as sum from orders group by month)

public function index()
    {
        $categories_count = Category::count();
        $products_count = Product::count();   
        $users_count = User::count();
        $orders_count = Order::count();

        $sales_data = Order::select(
            DB::raw('YEAR(created_at) as year'),
            DB::raw('MONTH(created_at) as month'),
            DB::raw('SUM(grand_total) as sum')
        )->groupBy('month')->get();

        dd($sales_data);

        return view('dashboard.index', compact('categories_count', 'products_count','users_count','orders_count','sales_data'));

    }//end of index
}

@push('scripts')

    <script>
        //line chart
        var line = new Morris.Line({
            element: 'line-chart',
            resize: true,
            data: [
                @foreach ($sales_data as $data)
                {
                    ym: "{{ $data->year }}-{{ $data->month }}", sum: "{{ $data->sum }}"
                },
                @endforeach
            ],
            xkey: 'ym',
            ykeys: ['sum'],
            labels: ['@lang('site.total')'],
            lineWidth: 2,
            hideHover: 'auto',
            gridStrokeWidth: 0.4,
            pointSize: 4,
            gridTextFamily: 'Open Sans',
            gridTextSize: 10
        });
    </script> @endpush
David Buck
  • 3,752
  • 35
  • 31
  • 35
  • You can't have GROUP BY on no aggregate columns on Standard SQL. You want, must use anyway you must disable it. Use the command on your MySQL: SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); or checkout this answer: https://stackoverflow.com/questions/23921117/disable-only-full-group-by – Luís Assunção Mar 08 '20 at 00:52
  • the same problem – Tabet Med Islem Mar 08 '20 at 01:18

0 Answers0