Updated dashboard

This commit is contained in:
m.razaghi
2026-08-05 13:56:46 +03:30
parent 5aa2447e23
commit af21c1c77e
3 changed files with 10 additions and 28 deletions

View File

@@ -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();