diff --git a/app/Marhun.php b/app/Marhun.php index 301566c..88eff01 100644 --- a/app/Marhun.php +++ b/app/Marhun.php @@ -15,7 +15,7 @@ class Marhun extends Model * @var array */ protected $fillable = [ - 'kodcaw','marhun','t_gadai','norujukan','bil','nota','karat','berat','harga','n_marhun' + 'kodcaw','marhun','t_gadai','norujukan','bil','nota','karat','berat','harga','n_marhun','batu_permata','berat_batu_permata', ]; /** diff --git a/database/migrations/2024_01_24_125247_add_batu_permata_to_marhun.php b/database/migrations/2024_01_24_125247_add_batu_permata_to_marhun.php new file mode 100644 index 0000000..f1fcd30 --- /dev/null +++ b/database/migrations/2024_01_24_125247_add_batu_permata_to_marhun.php @@ -0,0 +1,78 @@ +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('marhun', function (Blueprint $table) use ($dbase) { + + $isBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'batu_permata'); + $isBatuPermataExist = Schema::connection($dbase)->hasColumn('marhun', 'berat_batu_permata'); + + if (!$isBatuPermataExist) { + $table->string('batu_permata')->nullable(); + $table->decimal('berat_batu_permata', 7, 2)->nullable(); + } + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $db_connection = $this->getActiveDB(); + + foreach ($db_connection as $dbase) { + $columns = ['batu_permata', 'berat_batu_permata']; + + + $columns_exist = array_filter($columns, function ($column) use ($dbase) { + return Schema::connection($dbase)->hasColumn('marhun', $column); + }); + + Schema::connection($dbase)->table('marhun', function (Blueprint $table) use ($columns_exist) { + foreach ($columns_exist as $column) { + $table->dropColumn($column); + } + }); + } + } +}