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
|
// Order tickets by updated_at so newly replied tickets jump to the top
|
||||||
$recentTickets = Ticket::with('user')->latest('updated_at')->take(5)->get();
|
$recentTickets = Ticket::with('user')->latest('updated_at')->take(5)->get();
|
||||||
|
|
||||||
// 5. Prepare Chart Data (Dynamic Dates Based on Actual Records)
|
// 5. Prepare Chart Data (Strictly the last 7 calendar days)
|
||||||
|
|
||||||
// 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')];
|
|
||||||
}
|
|
||||||
|
|
||||||
$chartDates = [];
|
$chartDates = [];
|
||||||
$newUsersData = [];
|
$newUsersData = [];
|
||||||
$paidSubsData = [];
|
$paidSubsData = [];
|
||||||
$freeSubsData = [];
|
$freeSubsData = [];
|
||||||
|
|
||||||
foreach ($recentDates as $dbDate) {
|
for ($i = 6; $i >= 0; $i--) {
|
||||||
// Add the date to the chart labels
|
$date = now()->subDays($i);
|
||||||
$chartDates[] = $dbDate;
|
$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
|
// Count records for this specific exact date
|
||||||
$newUsersData[] = User::whereDate('created_at', $dbDate)->count();
|
$newUsersData[] = User::whereDate('created_at', $dbDate)->count();
|
||||||
|
|||||||
@@ -145,7 +145,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{ optional($suggestion->user)->mobile ?? 'ناشناس' }}</td>
|
<td>{{ optional($suggestion->user)->mobile ?? 'ناشناس' }}</td>
|
||||||
<td title="{{ $suggestion->text }}">{{ Str::limit($suggestion->text, 40) }}</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>
|
</tr>
|
||||||
@empty
|
@empty
|
||||||
<tr><td colspan="3" class="text-center">پیشنهادی وجود ندارد</td></tr>
|
<tr><td colspan="3" class="text-center">پیشنهادی وجود ندارد</td></tr>
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
<div class="rightbar-overlay"></div>
|
<div class="rightbar-overlay"></div>
|
||||||
|
|
||||||
@include('admin.partial.scripts')
|
@include('admin.partial.scripts')
|
||||||
|
@yield('scripts')
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user