From f55b8bc58045dceb8c2fd691632b3fdb577c04cf Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 3 Nov 2025 12:10:34 +0100 Subject: [PATCH] Create CreateGarant.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vytvorenie CLi príkazu na pridanie Granata (ADMINA) do databázy. --- backend/app/Console/Commands/CreateGarant.php | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 backend/app/Console/Commands/CreateGarant.php diff --git a/backend/app/Console/Commands/CreateGarant.php b/backend/app/Console/Commands/CreateGarant.php new file mode 100644 index 0000000..cff78db --- /dev/null +++ b/backend/app/Console/Commands/CreateGarant.php @@ -0,0 +1,59 @@ +info('=== Vytvorenie garanta (admin) ==='); + + // Načítanie údajov interaktívne + $firstName = $this->ask('Zadaj krstné meno'); + $lastName = $this->ask('Zadaj priezvisko'); + $email = $this->ask('Zadaj email'); + + // Kontrola duplicity emailu + if (User::where('email', $email)->exists()) { + $this->error('Používateľ s týmto emailom už existuje.'); + return 1; + } + + $password = $this->secret('Zadaj heslo (nebude sa zobrazovať)'); + $phone = $this->ask('Zadaj telefón '); + + // Vytvorenie používateľa + $user = User::create([ + 'name' => $firstName . ' ' . $lastName, + 'first_name' => $firstName, + 'last_name' => $lastName, + 'email' => $email, + 'phone' => $phone, + 'role' => 'ADMIN', + 'password' => Hash::make($password), + ]); + + $this->info("\n Garant {$user->first_name} {$user->last_name} bol úspešne vytvorený s rolou ADMIN."); + $this->info("Email: {$user->email}"); + + return 0; + } +}