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

feat: update HomeController and home view to streamline visit statistics display

- Added conditional logic to display the minimum visit date only if visits are present.
- Removed the computation and display of the most visited pages for the past 24 hours, 7 days, and 30 days from both the controller and the view to simplify the statistics presented.
parent 6f87f0d0
No related branches found
No related tags found
No related merge requests found
Pipeline #1086 passed
......@@ -57,9 +57,12 @@ public function index(Request $request): View
now()->subDays(7)->format('Y-m-d') => 'Les 7 derniers jours',
now()->subDays(30)->format('Y-m-d') => 'Les 30 derniers jours',
now()->startOfMonth()->format('Y-m-d') => 'Ce mois-ci',
$visits->min('created_at')->format('Y-m-d') => 'Depuis le début',
];
if ($visits->isNotEmpty()) {
$periods[$visits->min('created_at')->format('Y-m-d')] = 'Depuis le début';
}
$startDate = $request->input('start_date', now()->subDays(30)->format('Y-m-d'));
$dateEnd = $request->input('end_date', now()->format('Y-m-d'));
......@@ -85,24 +88,6 @@ public function index(Request $request): View
->sortByDesc('count')
->values();
$mostVisitedPagesForPastTwentyFourHours = $visits->where('created_at', '>=', $now->copy()->subDay())
->groupBy('url')
->map(fn ($group, $url) => ['url' => $url, 'count' => $group->count()])
->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,
......@@ -113,9 +98,6 @@ public function index(Request $request): View
'mostVisitedPages' => $mostVisitedPages,
'periods' => $periods,
'selectedPeriod' => $selectedPeriod,
'mostVisitedPagesForPastTwentyFourHours' => $mostVisitedPagesForPastTwentyFourHours,
'mostVisitedPagesForPastSevenDays' => $mostVisitedPagesForPastSevenDays,
'mostVisitedPagesForPastThirtyDays' => $mostVisitedPagesForPastThirtyDays,
]);
}
}
......@@ -76,90 +76,6 @@
<div class="row g-4">
<!-- Pages les plus visitées -->
<div class="g-col-12 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">Pages les plus visitées (24H)</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 ($mostVisitedPagesForPastTwentyFourHours 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 (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 register or to comment