Add helpers file, add helper to deal with multidb con
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
if (!function_exists('getActiveCawanganDbConnection')) {
|
||||
|
||||
function getActiveCawanganDbConnection()
|
||||
{
|
||||
|
||||
$all_active_db_keys = array_filter(array_keys(config('database.connections')), function ($connection) {
|
||||
try {
|
||||
DB::connection($connection)->getPdo();
|
||||
return true;
|
||||
} catch (\Throwable $th) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$non_cawangan_database = ['lelong', 'online_arrahn', 'kaunterpkb'];
|
||||
|
||||
$all_cawangan_db = array_filter($all_active_db_keys, function ($db_key) use ($non_cawangan_database) {
|
||||
$isNotCawangan = in_array(config('database.connections.' . $db_key . '.database'), $non_cawangan_database);
|
||||
|
||||
if ($isNotCawangan) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
return $all_cawangan_db;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user