From 9db74a8453579a2432f05bcfeea5edfc25c87331 Mon Sep 17 00:00:00 2001 From: Sofiane Lasri-Trienpont <alasri250@gmail.com> Date: Sat, 22 Feb 2025 10:33:08 +0100 Subject: [PATCH] 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. --- app/Http/Controllers/Admin/HomeController.php | 26 +----- resources/views/admin/home.blade.php | 84 ------------------- 2 files changed, 4 insertions(+), 106 deletions(-) diff --git a/app/Http/Controllers/Admin/HomeController.php b/app/Http/Controllers/Admin/HomeController.php index 9fc2501..5dc8161 100644 --- a/app/Http/Controllers/Admin/HomeController.php +++ b/app/Http/Controllers/Admin/HomeController.php @@ -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, ]); } } diff --git a/resources/views/admin/home.blade.php b/resources/views/admin/home.blade.php index 46d75a7..2ecf3e2 100644 --- a/resources/views/admin/home.blade.php +++ b/resources/views/admin/home.blade.php @@ -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"> -- GitLab