Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Vicente123's avatar

Query Builder "addGroupBy()" function doesnt works.

Hi, I'm trying to use 2 groupBy in a query, found this "addGrpupBy" in the QueryBuilder.php file, so i thought it might work, but it doesn't. Here is the query.

$sessions = Session::select(array('sessions.display_name', 'sites.name', 'programs.name')) ->join('programs', 'programs.session_id', '=', 'sessions.id') ->join('sites', 'programs.site_id', '=', 'sites.id') ->join('applications', 'applications.program_id', '=', 'programs.id') ->groupBy('sites.name') ->addGroupBy('programs.name') ->get();

The error that i get: Call to undefined method Illuminate\Database\Query\Builder::addGroupBy()

0 likes
4 replies
Vicente123's avatar

@vladshoob The thing is that i want to get 3 columns at my collection, and that returns only 2. I dont even know if it's posible xD

vladshoob's avatar

I beleive you don't need array in select statement. If sessions has display_name column then it suppose to show up. If it is not then it is hidden in model or not exists.

1 like
Vicente123's avatar

The thing is that i wasn't renaming the columns so it never returned me the 3 values...thx

1 like

Please or to participate in this conversation.