2022_05_04_132749_add_user_disabled.php 932 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. use App\Models\Setting;
  3. use App\Models\User;
  4. use Illuminate\Database\Migrations\Migration;
  5. use Illuminate\Database\Schema\Blueprint;
  6. use Illuminate\Support\Facades\Schema;
  7. return new class extends Migration
  8. {
  9. /**
  10. * Run the migrations.
  11. *
  12. * @return void
  13. */
  14. public function up()
  15. {
  16. Schema::table('users', function (Blueprint $table) {
  17. $table->boolean('disabled');
  18. });
  19. $disabledUsers = Setting::where('key', 'disabled')->where('value', 1)->get();
  20. foreach($disabledUsers as $u) {
  21. $user = User::where('id', $u->user)->first();
  22. $user->disabled = true;
  23. $user->save();
  24. }
  25. }
  26. /**
  27. * Reverse the migrations.
  28. *
  29. * @return void
  30. */
  31. public function down()
  32. {
  33. Schema::table('users', function (Blueprint $table) {
  34. $table->dropColumn('disabled');
  35. });
  36. }
  37. };