Skip to content
Snippets Groups Projects
Verified Commit 439f1df7 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

feat(admin): add most visited pages statistics for the last 7 and 30 days

- Implemented logic in HomeController to calculate the most visited pages over the last 7 and 30 days.
- Updated the admin home view to display tables for these statistics.
parent c78b1db6
No related branches found
No related tags found
No related merge requests found
Pipeline #1044 passed
......@@ -61,6 +61,18 @@ public function index(): View
->sortByDesc('count')
->values();
$mostVisitedPagesForPastSevenDays = $visits->where('created_at', '>=', $now->copy()->subDays(7))
->groupBy('url')
->map(fn ($group, $url) => ['url' => $url, 'count' => $group->count()])
->sortByDesc('count')
->values();
$mostVisitedPagesForPastThirtyDays = $visits->where('created_at', '>=', $now->copy()->subDays(30))
->groupBy('url')
->map(fn ($group, $url) => ['url' => $url, 'count' => $group->count()])
->sortByDesc('count')
->values();
return view('admin.home', [
'totalVisitsPastTwentyFourHours' => $totalVisitsPastTwentyFourHours,
'totalVisitsPastSevenDays' => $totalVisitsPastSevenDays,
......@@ -70,6 +82,8 @@ public function index(): View
'visitsByCountry' => $visitsByCountry,
'mostVisitedPages' => $mostVisitedPages,
'mostVisitedPagesForPastTwentyFourHours' => $mostVisitedPagesForPastTwentyFourHours,
'mostVisitedPagesForPastSevenDays' => $mostVisitedPagesForPastSevenDays,
'mostVisitedPagesForPastThirtyDays' => $mostVisitedPagesForPastThirtyDays,
]);
}
}
......@@ -97,6 +97,62 @@
</div>
</div>
<div class="g-col-12 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Pages les plus visitées (7 jours)</h5>
<div class="table-responsive">
<table class="table table-striped align-middle">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Page</th>
<th scope="col">Nombre de visites</th>
</tr>
</thead>
<tbody>
@foreach ($mostVisitedPagesForPastSevenDays as $index => $page)
<tr>
<th scope="row">{{ $index + 1 }}</th>
<td>{{ $page['url'] }}</td>
<td>{{ $page['count'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="g-col-12 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Pages les plus visitées (30 jours)</h5>
<div class="table-responsive">
<table class="table table-striped align-middle">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Page</th>
<th scope="col">Nombre de visites</th>
</tr>
</thead>
<tbody>
@foreach ($mostVisitedPagesForPastThirtyDays as $index => $page)
<tr>
<th scope="row">{{ $index + 1 }}</th>
<td>{{ $page['url'] }}</td>
<td>{{ $page['count'] }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="g-col-12">
<div class="card">
<div class="card-body">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment