Skip to content

Commit

Permalink
Feat: More convenient super admin user creation command
Browse files Browse the repository at this point in the history
  • Loading branch information
nikspyratos committed Jul 4, 2024
1 parent e68066d commit c8491d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

namespace App\Console\Commands;

use App\Enumerations\Role;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use App\Enumerations\Role;

use function Laravel\Prompts\password;
use function Laravel\Prompts\text;

class CreateAdminUser extends Command
class CreateSuperAdminUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:create-admin-user';
protected $signature = 'app:create-admin-user {--name=} {--email=} {--password=}';

/**
* The console command description.
Expand All @@ -33,19 +33,29 @@ class CreateAdminUser extends Command
*/
public function handle(): void
{
$name = text(
label: 'What is your name?',
required: true
);
$email = text(
label: 'What is your email?',
required: true
);
$password = password(
label: 'What is your password?',
placeholder: 'Minimum 8 characters...',
required: true
);
$name = $this->option('name');
$email = $this->option('email');
$password = $this->option('password');

if (!$name) {
$name = text(
label: 'What is your name?',
required: true
);
}
if (!$email) {
$email = text(
label: 'What is your email?',
required: true
);
}
if (!$password) {
$password = password(
label: 'What is your password?',
placeholder: 'Minimum 8 characters...',
required: true
);
}
User::firstOrCreate(
[
'email' => $email,
Expand All @@ -54,9 +64,9 @@ public function handle(): void
'name' => $name,
'password' => Hash::make($password),
'email_verified_at' => now(),
'role' => Role::ADMIN,
'role' => Role::SUPER_ADMIN,
]
);
$this->info('Successfully created user - you may now log in at /admin and access Pulse at /pulse');
$this->info('Successfully created user - you may now log in at /admin and access Telescope at /telescope');
}
}
1 change: 1 addition & 0 deletions templates/app/Enumerations/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

enum Role: string
{
case SUPER_ADMIN = 'super admin';
case ADMIN = 'admin';
case USER = 'user';
}

0 comments on commit c8491d7

Please sign in to comment.