Syntax error or access violation: 1055 'new.chart_of_accounts.name' isn't in GROUP BY

`app
 / 
Http
 / 
Controllers
 / 
ReportController
.php

: 1616

When i open link its ShowS ME THIS ERROR

This is the complete code for a PHP Laravel controller named "TransactionController". The purpose of this controller is to manage the transactions of a user’s bank accounts.

The "index" method is the main method of the controller, which is executed when the user visits the transaction page. The method first checks if the user has the permission to manage transactions or not. If the user has the permission, then the method prepares the data needed to display the transactions page.

The first thing that the method does is to set the default filters for the transactions page. The filter variables are initialized with "All" values for the account and category. Then, the method fetches all bank accounts of the user and prepares a dropdown list of account holders. It also adds a "Stripe / Paypal" option in the dropdown list for transactions that are not related to any bank account.

Next, the method prepares the categories for the transactions. It fetches all categories of the user and prepares a dropdown list of categories for transactions. It also adds "Bill" and "Invoice" options in the dropdown list.

After preparing the filters, the method fetches all the transactions and bank accounts of the user for the given time range. The time range is specified by the user, which can be set using the start_month and end_month query parameters. If these parameters are not set, then the default time range is set to the last five months.

The method then checks if any account or category filters are set by the user. If the user has selected an account, then the transactions and accounts are filtered by the selected account. If the user has selected a category, then the transactions and accounts are filtered by the selected category.

Finally, the method returns the transaction index view with the necessary data, such as transactions, accounts, categories, and filters.

If the user does not have the permission to manage transactions, then the method redirects the user to the previous page with an error message.

            $end   = $request->end_date;

        }

        else

        {

            $start = date('Y-m-01');

            $end   = date('Y-m-t');

        }



        $journalItem = JournalItem::select('chart_of_accounts.name', \DB::raw('sum(credit) as totalCredit'), \DB::raw('sum(debit) as totalDebit'), \DB::raw('sum(credit) - sum(debit) as netAmount'));

        $journalItem->leftjoin('journal_entries', 'journal_entries.id', 'journal_items.journal');

        $journalItem->leftjoin('chart_of_accounts', 'journal_items.account', 'chart_of_accounts.id');

        $journalItem->where('chart_of_accounts.created_by',\Auth::user()->creatorId());

        $journalItem->where('journal_items.created_at', '>=', $start);

        $journalItem->where('journal_items.created_at', '<=', $end);

        $journalItem->groupBy('account');

        $journalItem = $journalItem->get()->toArray();



        $filter['startDateRange'] = $start;

        $filter['endDateRange']   = $end;



        return view('report.trial_balance', compact('filter', 'journalItem'));

    }

    else

    {

        return redirect()->back()->with('error', __('Permission Denied.'));

    }

}

public function leave(Request $request)

{`

SQLSTATE[42000]: Syntax error or access violation: 1055 'new.chart_of_accounts.name' isn't in GROUP BY (Connection: mysql, SQL: select chart_of_accounts.name, sum(credit) as totalCredit, sum(debit) as totalDebit, sum(credit) - sum(debit) as netAmount from journal_itemsleft joinjournal_entriesonjournal_entries.id=journal_items.journalleft joinchart_of_accountsonjournal_items.account=chart_of_accounts.idwherechart_of_accounts.created_by= 2 andjournal_items.created_at>= 2023-04-01 andjournal_items.created_at<= 2023-04-30 group byaccount`)

`

Trying to solve this issue

>Solution :

Instead of

$journalItem->groupBy('account');

Use

 $journalItem->groupBy('chart_of_accounts.name');

All column gave to be in th group by or have an aggregation from nction, so when you group by account, it mus be in the select and name needs an aggregation function, or you use name to group by

Leave a Reply