2023_06_04_224713_update_paypal.php 1004 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. use App\Models\Config;
  3. use Illuminate\Database\Migrations\Migration;
  4. return new class extends Migration
  5. {
  6. private static array $dropConfigs = ['paypal_username', 'paypal_password', 'paypal_secret', 'paypal_certificate'];
  7. private static array $newConfigs = ['paypal_client_id', 'paypal_client_secret'];
  8. /**
  9. * Run the migrations.
  10. */
  11. public function up(): void
  12. {
  13. if (Config::exists()) {
  14. foreach (self::$newConfigs as $config) {
  15. Config::insert(['name' => $config]);
  16. }
  17. foreach (self::$dropConfigs as $config) {
  18. Config::destroy(['name' => $config]);
  19. }
  20. }
  21. }
  22. /**
  23. * Reverse the migrations.
  24. */
  25. public function down(): void
  26. {
  27. foreach (self::$newConfigs as $config) {
  28. Config::destroy(['name' => $config]);
  29. }
  30. foreach (self::$dropConfigs as $config) {
  31. Config::insert(['name' => $config]);
  32. }
  33. }
  34. };