ensureCrmSubscription(); $scope = CustomerMaintenanceScopeService::forCurrentUser(); $schedules = $scope->preventiveScheduleQuery() ->with(['equipment:id,name,code', 'project:id,name', 'productionLine:id,name']) ->orderByRaw('next_due_at IS NULL, next_due_at ASC') ->paginate(20); return view('portal::customer.periodic_services.index', compact('schedules')); } public function show($id) { $this->ensureCrmSubscription(); $scope = CustomerMaintenanceScopeService::forCurrentUser(); if (! $scope->ownsPreventiveSchedule((int) $id)) { abort(404); } $schedule = $scope->preventiveScheduleQuery() ->with(['equipment', 'project', 'productionLine', 'assignedUser:id,first_name,last_name']) ->findOrFail($id); $workOrders = $scope->workOrderQuery() ->where('preventive_schedule_id', $schedule->id) ->with(['equipment:id,name', 'assignedTechnician:id,first_name,last_name']) ->orderByDesc('created_at') ->get(); return view('portal::customer.periodic_services.show', compact('schedule', 'workOrders')); } }