feat: laravel prompts
CI / 🧪 Tests Laravel (push) Successful in 2m31s
CI / 🐳 Build & Push Image (push) Successful in 39s

This commit is contained in:
2026-08-13 09:45:00 +02:00
parent 29e85589b0
commit 5702ad88e4
+39 -11
View File
@@ -10,6 +10,13 @@ use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Password;
use function Laravel\Prompts\error;
use function Laravel\Prompts\intro;
use function Laravel\Prompts\outro;
use function Laravel\Prompts\password;
use function Laravel\Prompts\select;
use function Laravel\Prompts\text;
class CreateUser extends Command
{
protected $signature = 'user:create
@@ -23,12 +30,26 @@ class CreateUser extends Command
public function handle(): int
{
$name = trim((string) ($this->option('name') ?: $this->ask('Name')));
$email = strtolower(trim((string) ($this->option('email') ?: $this->ask('Email address'))));
$role = (string) ($this->option('role') ?: $this->choice(
'Role',
array_column(UserRole::cases(), 'value'),
UserRole::USER->value,
intro('Create a Bowli user');
$name = trim((string) ($this->option('name') ?: text(
label: 'User name',
placeholder: 'e.g. jane.doe',
required: true,
hint: '3 to 32 characters: letters, numbers, dots, hyphens, or underscores.',
)));
$email = strtolower(trim((string) ($this->option('email') ?: text(
label: 'Email address',
placeholder: 'e.g. jane@example.com',
required: true,
))));
$role = (string) ($this->option('role') ?: select(
label: 'Role',
options: collect(UserRole::cases())
->mapWithKeys(fn (UserRole $role): array => [$role->value => ucfirst($role->value)])
->all(),
default: UserRole::USER->value,
hint: 'Choose the permissions granted to this user.',
));
$locale = strtolower(trim((string) $this->option('locale')));
@@ -46,14 +67,21 @@ class CreateUser extends Command
if ($attributesValidator->fails()) {
foreach ($attributesValidator->errors()->all() as $error) {
$this->components->error($error);
error($error);
}
return self::FAILURE;
}
$password = (string) $this->secret('Password');
$passwordConfirmation = (string) $this->secret('Confirm password');
$password = password(
label: 'Password',
required: true,
hint: 'At least 8 characters with uppercase, lowercase, number, and symbol.',
);
$passwordConfirmation = password(
label: 'Confirm password',
required: true,
);
$passwordValidator = Validator::make([
'password' => $password,
@@ -72,7 +100,7 @@ class CreateUser extends Command
if ($passwordValidator->fails()) {
foreach ($passwordValidator->errors()->all() as $error) {
$this->components->error($error);
error($error);
}
return self::FAILURE;
@@ -87,7 +115,7 @@ class CreateUser extends Command
'role' => UserRole::from($role),
]);
$this->components->info("User {$user->email} created with ID {$user->getKey()} and role {$user->role->value}.");
outro("User {$user->email} created with ID {$user->getKey()} and role {$user->role->value}.");
return self::SUCCESS;
}