-
app/Services/AppointmentService.php
Open in GitHubuse App\Models\Appointment; class AppointmentService { public function getAppointments($today = false, $confirmed = true) { return Appointment::query() ->with(['patient' => function ($query) { $query->select([ 'id', 'name', 'weight', 'phone_number', 'patient_id', ]); }], ['location' => function ($query) { $query->select([ 'location.name', ]); }]) ->when($today, function ($query) { $query->where('date', now()->format('Y-m-d')); }) ->when($confirmed === true, function ($query) { $query->where('visited', 1)->where('time', '!=', null); }) ->when($confirmed === false, function ($query) { $query->where('visited', 0); }) ->orderByDesc('date') ->orderByDesc('id') ->paginate(20); } }
-
app/Http/Controllers/DoctorController.php
Open in GitHubuse App\Services\AppointmentService; use Inertia\Inertia; class DoctorController extends Controller { public function index(AppointmentService $appointmentService) { $appointments = $appointmentService->getAppointments(true, true); return Inertia::render('DoctorDashboard') ->with('appointments', $appointments); } }