Files
HickLab3D_Dashboard/app/Console/Commands/CreateAdmin.php
T
Hickmeister 88dd00551f
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 19s
Migrate HickLab3D dashboard and add production auto deployment
2026-10-10 18:51:23 +01:00

35 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
#[Signature('app:create-admin {username} {email}')]
#[Description('Create the first HickLab3D administrator')]
class CreateAdmin extends Command
{
public function handle(): int
{
$username = (string) $this->argument('username');
$email = (string) $this->argument('email');
if (User::where('username', $username)->orWhere('email', $email)->exists()) {
$this->error('That username or email already exists.');
return self::FAILURE;
}
$password = (string) $this->secret('Password (at least 12 characters)');
if (mb_strlen($password) < 12) {
$this->error('Password is too short.');
return self::FAILURE;
}
User::create(['username' => $username, 'email' => $email, 'role' => 'admin', 'password' => $password]);
$this->info('Administrator created.');
return self::SUCCESS;
}
}