Updated dashboard
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
<tr>
|
||||
<td>{{ optional($suggestion->user)->mobile ?? 'ناشناس' }}</td>
|
||||
<td title="{{ $suggestion->text }}">{{ Str::limit($suggestion->text, 40) }}</td>
|
||||
<td dir="ltr">{{ $suggestion->created_at->format('Y/m/d H:i') }}</td>
|
||||
<td dir="ltr">{{ \Morilog\Jalali\Jalalian::fromCarbon($suggestion->created_at)->format('Y/m/d H:i') }}</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="3" class="text-center">پیشنهادی وجود ندارد</td></tr>
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
<div class="rightbar-overlay"></div>
|
||||
|
||||
@include('admin.partial.scripts')
|
||||
@yield('scripts')
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user