Skip to content

Commit f25ad8a

Browse files
authored
Added scopeByPage method
1 parent 854751e commit f25ad8a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Models/Pageview.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public function scopeDaily(Builder $query): Builder
1616
->orderBy('date', 'desc');
1717
}
1818

19+
public function scopeByPage(Builder $query): Builder
20+
{
21+
return $query->selectRaw('COUNT(*) views, path, COUNT(DISTINCT visitorid) unique_visitors, MAX(created_at) latest_visit')
22+
->groupBy('path');
23+
}
24+
1925
public function scopeWithoutBots(Builder $query): Builder
2026
{
2127
return $query->where('useragent', 'not like', '%bot%')
@@ -29,7 +35,6 @@ public function scopeWithoutBots(Builder $query): Builder
2935
public function scopeUniqueVisitors(Builder $query): Builder
3036
{
3137
return $query->selectRaw('COUNT(DISTINCT visitorid) unique_visitors, DATE(created_at) date')
32-
->groupBy(['date'])
33-
->orderBy('date', 'desc');
38+
->groupBy(['date']);
3439
}
35-
}
40+
}

0 commit comments

Comments
 (0)