ensureCrmSubscription(); $scope = CustomerMaintenanceScopeService::forCurrentUser(); $lines = $scope->productionLineQuery() ->with(['project:id,name']) ->withCount('equipment') ->orderBy('name') ->paginate(20); return view('portal::customer.production_lines.index', compact('lines')); } public function show($id) { $this->ensureCrmSubscription(); $scope = CustomerMaintenanceScopeService::forCurrentUser(); if (! $scope->ownsProductionLine((int) $id)) { abort(404); } $line = $scope->productionLineQuery() ->with([ 'project', 'equipment' => fn ($q) => $q->orderBy('name'), ]) ->findOrFail($id); $schedules = $scope->preventiveScheduleQuery() ->where('production_line_id', $line->id) ->with('equipment:id,name') ->orderBy('next_due_at') ->get(); $workOrders = $scope->workOrderQuery() ->where('production_line_id', $line->id) ->with(['equipment:id,name', 'assignedTechnician:id,first_name,last_name']) ->orderByDesc('created_at') ->limit(15) ->get(); return view('portal::customer.production_lines.show', compact('line', 'schedules', 'workOrders')); } }