From af21c1c77e080ec523cef95081f590c02d1ad54b Mon Sep 17 00:00:00 2001 From: "m.razaghi" Date: Wed, 5 Aug 2026 13:56:46 +0330 Subject: [PATCH] Updated dashboard --- .../Controllers/Admin/DashboardController.php | 33 ++++--------------- .../views/admin/dashboard/index.blade.php | 2 +- resources/views/admin/layouts/app.blade.php | 3 +- 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index f7aa374..8a2d08d 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -44,37 +44,18 @@ class DashboardController extends Controller // Order tickets by updated_at so newly replied tickets jump to the top $recentTickets = Ticket::with('user')->latest('updated_at')->take(5)->get(); - // 5. Prepare Chart Data (Dynamic Dates Based on Actual Records) - - // Grab the 7 most recent unique dates where users actually registered - $recentDates = User::latest('created_at') - ->take(200) // Look through the last 200 users to find distinct dates - ->get() - ->pluck('created_at') - ->map(function ($date) { - // Ensure we get a standard Y-m-d string for querying - return $date ? $date->format('Y-m-d') : null; - }) - ->filter() - ->unique() - ->take(7) - ->sort() // Sort chronologically (oldest to newest) - ->values() - ->toArray(); - - // Fallback just in case the database is completely empty - if (empty($recentDates)) { - $recentDates = [now()->format('Y-m-d')]; - } - + // 5. Prepare Chart Data (Strictly the last 7 calendar days) $chartDates = []; $newUsersData = []; $paidSubsData = []; $freeSubsData = []; - foreach ($recentDates as $dbDate) { - // Add the date to the chart labels - $chartDates[] = $dbDate; + for ($i = 6; $i >= 0; $i--) { + $date = now()->subDays($i); + $dbDate = $date->format('Y-m-d'); + + // Format X-axis to Jalali for the chart labels + $chartDates[] = \Morilog\Jalali\Jalalian::fromCarbon($date)->format('Y/m/d'); // Count records for this specific exact date $newUsersData[] = User::whereDate('created_at', $dbDate)->count(); diff --git a/resources/views/admin/dashboard/index.blade.php b/resources/views/admin/dashboard/index.blade.php index e715396..564c692 100644 --- a/resources/views/admin/dashboard/index.blade.php +++ b/resources/views/admin/dashboard/index.blade.php @@ -145,7 +145,7 @@ {{ optional($suggestion->user)->mobile ?? 'ناشناس' }} {{ Str::limit($suggestion->text, 40) }} - {{ $suggestion->created_at->format('Y/m/d H:i') }} + {{ \Morilog\Jalali\Jalalian::fromCarbon($suggestion->created_at)->format('Y/m/d H:i') }} @empty پیشنهادی وجود ندارد diff --git a/resources/views/admin/layouts/app.blade.php b/resources/views/admin/layouts/app.blade.php index 86fd08a..ede33ab 100644 --- a/resources/views/admin/layouts/app.blade.php +++ b/resources/views/admin/layouts/app.blade.php @@ -43,6 +43,7 @@
@include('admin.partial.scripts') + @yield('scripts') - \ No newline at end of file +