costUnit = $costUnit; } public function toArray($request) { $totalAmount = 0; $donatedAmount = 0; $countNewInvoices = 0; $countApprovedInvoices = 0; $countDonatedInvoices = 0; $countDeniedInvoices = 0; $data = array_merge( $this->costUnit->toArray(), [ 'distanceAllowanceSmall' => new Amount($this->costUnit->distance_allowance, '')->toString(), 'distanceAllowanceFull' => new Amount($this->costUnit->distance_allowance, ' Euro')->toString(), 'totalAmount' => new Amount($totalAmount, ' Euro')->toString(), 'donatedAmount' => new Amount($donatedAmount, ' Euro')->toString(), 'countNewInvoices' => $countNewInvoices, 'countApprovedInvoices' => $countApprovedInvoices, 'countDonatedInvoices' => $countDonatedInvoices, 'countDeniedInvoices' => $countDeniedInvoices, 'treasurers' => $this->costUnit->tresurers()->get()->map(fn($user) => new UserResource($user))->toArray(), ]); return $data; } }