diff --git a/src/SearchableTrait.php b/src/SearchableTrait.php index edfab7e..47f944b 100644 --- a/src/SearchableTrait.php +++ b/src/SearchableTrait.php @@ -120,14 +120,25 @@ protected function makeJoins(&$query) protected function makeGroupBy(&$query) { $driver = $this->getDatabaseDriver(); - if ($driver == 'sqlsrv') { $columns = $this->getTableColumns(); } else { - $columns = $this->primaryKey; - } + $id = $this->getTable() . '.' .$this->primaryKey; + $joins = array_keys(($this->getJoins())); + + foreach ($this->getColumns() as $column => $relevance) { + + array_map(function($join) use ($column, $query){ - $query->groupBy($columns); + if(Str::contains($column, $join)){ + $query->groupBy("$column"); + } + + }, $joins); + + } + } + $query->groupBy($id); } /**