AdminReset.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\User;
  4. use Illuminate\Console\Command;
  5. class AdminReset extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'chemex:admin-reset';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '重置Admin账户';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int|void
  32. */
  33. public function handle(): int
  34. {
  35. $user = User::where('username', 'admin')->first();
  36. if (empty($user)) {
  37. $user = new User();
  38. $user->username = 'admin';
  39. }
  40. $user->password = bcrypt('admin');
  41. $user->name = 'Administrator';
  42. $user->save();
  43. $this->info('Admin账户已成功重置为 admin/admin');
  44. return 0;
  45. }
  46. }