si-klinik/sk-klinik.my.id/app/Livewire/Admin/Dashboard.php

35 lines
1.1 KiB
PHP

<?php
namespace App\Livewire\Admin;
use App\Models\Patient;
use App\Models\Appointment;
use App\Models\Doctor;
use App\Models\News;
use Livewire\Component;
class Dashboard extends Component
{
public function render()
{
// Menggunakan date() jauh lebih aman dari error argumen
$today = date('Y-m-d');
return view('livewire.admin.dashboard', [
'stats' => [
'total_patients' => Patient::count(),
'today_appointments' => Appointment::whereDate('appointment_date', $today)->count(),
'total_doctors' => Doctor::count(),
'published_news' => News::where('is_published', true)->count(),
],
'recentAppointments' => Appointment::with(['patient', 'serviceCategory'])
->whereDate('appointment_date', $today)
->whereIn('status', ['waiting', 'calling'])
->orderBy('queue_number', 'asc')
->take(5)
->get(),
'popularNews' => News::orderBy('view_count', 'desc')->take(5)->get(),
]);
}
}