Files
HeimerdingerLoL/app/Console/Commands/UserCreateCommand.php
Rico van Zelst 2374a39c77 feat(monitoring): add pulse
- Added a new gate called `viewPulse` in the `AuthServiceProvider` class.
- The gate allows only admin users to view the Pulse feature.
2023-12-01 21:49:26 +01:00

52 lines
1.4 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class UserCreateCommand extends Command
{
protected $signature = 'user:create';
protected $description = 'Create a new user from CLI';
public function handle(): void
{
if (config('app.env') === 'production') {
if (!$this->confirm('You are in production mode. Are you sure you want to continue?')) {
return;
}
}
$this->info('Creating a new user...');
$name = $this->ask('Name');
$email = $this->ask('Email');
$password = $this->secret('Password');
$password_confirmation = $this->secret('Confirm password');
$admin = $this->confirm('Is this user an admin?');
$this->info('Name: ' . $name);
$this->info('Email: ' . $email);
$this->info('Password: ' . $password);
$this->info('Password confirmation: ' . $password_confirmation);
$this->info('Admin: ' . $admin);
if ($password !== $password_confirmation) {
$this->error('Passwords do not match!');
return;
}
$user = User::create([
'name' => $name,
'email' => $email,
'password' => bcrypt($password),
'admin' => $admin,
]);
$this->info('User with name ' . $user->name . 'created successfully.');
}
}