You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/CountMetaProvider.php
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
<?phpnamespaceMarcelgwerder\ApiHandler;
2
2
3
+
useIlluminate\Support\Facades\DB;
4
+
3
5
class CountMetaProvider extends MetaProvider
4
6
{
5
7
/**
@@ -28,6 +30,17 @@ public function __construct($title, $builder)
28
30
*/
29
31
publicfunctionget()
30
32
{
33
+
if (!empty($this->builder->groups)) {
34
+
//Only a count column is required
35
+
$this->builder->columns = [];
36
+
$this->builder->selectRaw('count(*) as aggregate');
37
+
$this->builder->limit = null;
38
+
39
+
//Use the original builder as a subquery and count over it because counts over groups return the number of rows for each group, not for the total results
40
+
$query = DB::query()->selectRaw('count(*) as aggregate from (' . $this->builder->toSql() . ') as count_table', $this->builder->getBindings());
0 commit comments