authorize('view', $customer); $companyId = $request->header('company'); $previousYear = $request->has('previous_year'); $chartData = $this->customerStatsProvider->get($customer, $companyId, $previousYear); // The row is read a second time instead of reusing the bound instance. // Nothing the provider does requires it, but the reload is what the // resource ends up rendering, so it stays. $fresh = Customer::query()->find($customer->id); $this->customerStatementQuery->hydrateAccountSummaries([$fresh]); return (new CustomerResource($fresh)) ->additional(['meta' => ['chartData' => $chartData]]); } }