2025_12_14_025944_create_admin_table.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. use Illuminate\Support\Facades\Hash; // 添加这个
  6. use Illuminate\Support\Facades\DB; // 添加这个
  7. return new class extends Migration
  8. {
  9. /**
  10. * Run the migrations.
  11. */
  12. public function up(): void
  13. {
  14. Schema::create('admin', function (Blueprint $table) {
  15. $table->id();
  16. $table->string('account', 50)->unique()->comment('账号'); // 账号,唯一
  17. $table->string('nickname', 50)->comment('昵称'); // 昵称
  18. $table->string('password')->comment('密码'); // 密码
  19. $table->tinyInteger('status')->default(1)->comment('状态:0-禁用,1-启用'); // 状态
  20. $table->timestamps();
  21. $table->index('account');
  22. $table->index('status');
  23. });
  24. // 在表创建后插入超级管理员数据
  25. DB::table('admin')->insert([
  26. 'account' => 'admin',
  27. 'nickname' => '超级管理员',
  28. 'password' => Hash::make('123456'), // 请修改这个默认密码
  29. 'status' => 1,
  30. 'created_at' => now(),
  31. 'updated_at' => now(),
  32. ]);
  33. }
  34. /**
  35. * Reverse the migrations.
  36. */
  37. public function down(): void
  38. {
  39. Schema::dropIfExists('admin');
  40. }
  41. };