Level 11
Issue solved
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i have a function that gets list of banks from Flutterwave. now what i get from Flutterwave api is bank name bank code and bank id.
public function handle()
{
try {
// Making the API request
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . env('FLUTTERWAVE_SECRET_KEY'),
])->get(env('FLUTTERWAVE_BASE_URL') . '/v3/banks/NG');
if ($response->successful()) {
$banksData = $response->json()['data']; // Getting data from the response
foreach ($banksData as $bankData) {
// Assuming you have 'id', 'code', and 'name' columns in your 'ng_banks_lists' table
NgBanksList::updateOrCreate(
['bank_id' => $bankData['id']], // Match on bank_id (assumed to be 'id')
[
'bank_code' => $bankData['code'], // Update or insert the bank code
'bank_name' => $bankData['name'], // Update or insert the bank name
]
);
// Log each bank update
Log::info('Updated: ' . $bankData['name'] . ' (Code: ' . $bankData['code'] . ')');
}
// Log success after all updates
Log::info('Bank list updated successfully.');
} else {
// Log API error
Log::error('Failed to fetch bank data from the API. Response status: ' . $response->status());
}
return 0;
} catch (\Exception $e) {
// Handle API errors or exceptions
Log::error('Error: ' . $e->getMessage());
return 1;
}
}
i have an array of banks and code now i want to check if the banks fetched from Flutterwave are similar to the banks on the array if there are any that are similar let's say Zenith Bank and Zenith Bank plc, fetch the code in the array and save together with bank_id, bank_name, and bank_code and code to the Db but if the bank is not on the array list save the code of that bank to db as null the array is
// Predefined bank codes and names
protected $predefinedBanks = [
'Sterling Bank' => '000001',
'Keystone Bank' => '000002',
'FCMB' => '000003',
'United Bank for Africa' => '000004',
'Diamond Bank' => '000005',
'JAIZ Bank' => '000006',
];
Please or to participate in this conversation.