From c33286fe938b0008376b02b8d4048061eb7e41af Mon Sep 17 00:00:00 2001 From: Stefano Mazzega Date: Thu, 24 Aug 2023 17:35:15 +0200 Subject: [PATCH] fix column-sortable not working with withCount() #49 fix #49 https://github.com/Kyslik/column-sortable/issues/49 --- src/ColumnSortable/Sortable.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ColumnSortable/Sortable.php b/src/ColumnSortable/Sortable.php index c4fcebb..a7b6540 100755 --- a/src/ColumnSortable/Sortable.php +++ b/src/ColumnSortable/Sortable.php @@ -219,6 +219,10 @@ private function formJoin($query, $parentTable, $relatedTable, $parentPrimaryKey { $joinType = config('columnsortable.join_type', 'leftJoin'); - return $query->select($parentTable.'.*')->{$joinType}($relatedTable, $parentPrimaryKey, '=', $relatedPrimaryKey); + if ($query->getQuery()->columns === null) { + $query->select($parentTable.'.*'); + } + + return $query->{$joinType}($relatedTable, $parentPrimaryKey, '=', $relatedPrimaryKey); } }