Add user:create artisan command
All checks were successful
Setup EC2 Tools / setup-server (push) Successful in 1m31s
All checks were successful
Setup EC2 Tools / setup-server (push) Successful in 1m31s
This commit is contained in:
parent
37772f4c3f
commit
daf9d45c53
1 changed files with 43 additions and 0 deletions
43
app/Console/Commands/CreateUserCommand.php
Normal file
43
app/Console/Commands/CreateUserCommand.php
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Actions\User\CreateUser;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CreateUserCommand extends Command
|
||||
{
|
||||
protected $signature = 'user:create {email? : The email address of the user} {--name= : The name of the user} {--password= : The password for the user}';
|
||||
|
||||
protected $description = 'Create a new user with account and default workspace';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$email = $this->argument('email') ?? $this->ask('User email');
|
||||
if (User::where('email', $email)->exists()) {
|
||||
$this->error("A user with email {$email} already exists.");
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$name = $this->option('name') ?? $this->ask('User name', 'Admin');
|
||||
$password = $this->option('password') ?? $this->secret('User password');
|
||||
|
||||
if (! $password) {
|
||||
$this->error('Password cannot be empty.');
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$user = CreateUser::execute([
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
]);
|
||||
|
||||
$this->info("User [{$user->email}] created successfully with personal account and workspace!");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue