add tunggakan for onepercent and ujrah

This commit is contained in:
Hafifie PKB
2023-12-13 23:55:10 +08:00
parent ab4be6cf11
commit b5b98d0fdf
7 changed files with 236 additions and 50 deletions
@@ -0,0 +1,69 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
class AddTunggakanToGadaiTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
/**
*
* @var object $db_connection
*/
public function getActiveDB(){
$config_db = array_keys(config("database.connections"));
$db_connection = array_filter($config_db,function($connection){
try{
if($connection == 'mysql7')
return false;
$db = DB::connection($connection)->getPdo();
return true;
} catch(\Exception $e){
return false;
}
});
return $db_connection;
}
public function up()
{
$db_connection = $this->getActiveDB();
foreach($db_connection as $dbase){
Schema::connection($dbase)->table('gadai', function (Blueprint $table) {
$table->decimal('tunggakanujrah', 9, 2);
$table->decimal('tunggakanonepercent', 9, 2);
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$db_connection = $this->getActiveDB();
foreach($db_connection as $dbase){
if (Schema::connection('mysql7')->hasColumn('tunggakanujrah','tunggakanonepercent')){
Schema::connection($dbase)->table('gadai', function (Blueprint $table) {
$table->dropColumn(['tunggakanujrah','tunggakanonepercent']);
});
}
}
}
}