Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

81 rinda
1.6KB

  1. <?php
  2. namespace App\Console\Commands\Test;
  3. use App\Codes\UserRole;
  4. use App\Console\Commands\BaseCommand;
  5. use App\Models\User;
  6. use App\Util\DBUtil;
  7. use Exception;
  8. use Illuminate\Support\Facades\Hash;
  9. class 管理者ユーザー登録 extends BaseCommand
  10. {
  11. const COMMAND = "test:make-admin-user";
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = self::COMMAND;
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = '管理者ユーザーを登録する';
  24. static public function getCommand()
  25. {
  26. return self::COMMAND;
  27. }
  28. /**
  29. * Create a new command instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct()
  34. {
  35. parent::__construct();
  36. }
  37. /**
  38. * Execute the console command.
  39. *
  40. * @return int
  41. */
  42. public function service(): int
  43. {
  44. $db = new DBUtil();
  45. try {
  46. $db->beginTransaction();
  47. // 管理者ログインユーザーの作成
  48. $user = User::whereEmail("admin@aa.com")
  49. ->firstOrNew();
  50. $user->name = "管理者";
  51. $user->email = "admin@aa.com";
  52. $user->role = UserRole::ADMIN;
  53. // $user->password = Hash::make("testuser");
  54. $user->password = "testuser";
  55. $user->save();
  56. $db->commit();
  57. } catch (Exception $e) {
  58. $db->rollBack();
  59. throw $e;
  60. }
  61. return self::RESULTCODE_SUCCESS;
  62. }
  63. }