validate($request, [ 'country_id' => 'nullable|integer|exists:countries,id' ]); $country = CountriesCurrency::findOrFail($request->input('country_id')); $insurances = DB::select("SELECT n.id , n.name , nhc.age_limit_of_insured_and_spouse, nhc.age_limit_of_child_beneficiary, nhc.max_number_of_beneficiaries, nhc.id as nhc_id FROM networks n JOIN configWallet cw ON cw.id_network = n.id JOIN nh_networks_configs nhc ON nhc.network_id = n.id WHERE n.country_id = :countryId AND cw.type = 'ilink_sante' AND n.status = 1", ['countryId' => $request->input('country_id')]); foreach ($insurances as $insurance) { $months_prices = DB::select("SELECT id, number_of_months , min_amount FROM nh_months_prices_grid WHERE nh_network_config_id = :nhc_id", ['nhc_id' => $insurance->nhc_id]); foreach ($months_prices as $mp) { $mp->min_amount = $this->toMoneyWithCurrencyCode($mp->min_amount, $country->currency_code ?? 'XAF'); } $insurance->months_prices = $months_prices; unset($insurance->nhc_id); } return $this->successResponse($insurances); } }