authorizeAbility($request, 'feedback.view'); $owner = $this->ownerRef($request); $organization = $this->organization($request); $branchScope = app(OrganizationResolver::class)->branchScope($this->member($request)); $feedback = CustomerFeedback::owned($owner) ->where('organization_id', $organization->id) ->when($branchScope, fn ($q) => $q->whereHas('ticket', fn ($t) => $t->where('branch_id', $branchScope))) ->with(['ticket', 'counter']) ->latest() ->paginate(30); $avgRating = CustomerFeedback::owned($owner) ->where('organization_id', $organization->id) ->when($branchScope, fn ($q) => $q->whereHas('ticket', fn ($t) => $t->where('branch_id', $branchScope))) ->avg('rating'); return view('qms.feedback.index', [ 'feedback' => $feedback, 'organization' => $organization, 'avgRating' => round((float) $avgRating, 1), ]); } }