Files
core/src/Command/CreateAdminCommand.php
T
Konstantinos Arvanitakis 9f58a36c82 Init
2026-07-01 18:35:39 +03:00

43 lines
1.3 KiB
PHP

<?php
namespace Modules\Core\Command;
use Lunar\Admin\Console\Commands\MakeLunarAdminCommand;
use function Laravel\Prompts\text;
class CreateAdminCommand extends MakeLunarAdminCommand
{
protected $signature = 'lunar:create-admin
{--firstname= : The first name of the user}
{--lastname= : The last name of the user}
{--email= : A valid and unique email address}';
protected function getUserData(): array
{
return [
'first_name' => $this->options['firstname'] ?? text(
label: 'First Name',
required: true,
),
'last_name' => $this->options['lastname'] ?? text(
label: 'Last Name',
required: true,
),
'email' => $this->options['email'] ?? text(
label: 'Email address',
required: true,
validate: fn (string $email): ?string => match (true) {
! filter_var($email, FILTER_VALIDATE_EMAIL) => 'The email address must be valid.',
\Lunar\Admin\Models\Staff::where('email', $email)->exists() => 'A user with this email address already exists',
default => null,
},
),
'admin' => true,
];
}
}