Files
event-uploader/api/app/Console/Commands/MakeAdminUser.php
2026-02-03 10:38:46 +01:00

45 lines
1.2 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
class MakeAdminUser extends Command
{
protected $signature = 'make:admin
{--email= : Admin email address}
{--password= : Admin password}';
protected $description = 'Create an admin user (email and password required)';
public function handle(): int
{
$email = $this->option('email');
$password = $this->option('password');
if (! $email || ! $password) {
$this->error('Please provide --email and --password.');
$this->line('Example: php artisan make:admin --email=admin@example.com --password=secret');
return self::FAILURE;
}
if (User::where('email', $email)->exists()) {
$this->error("A user with email {$email} already exists.");
return self::FAILURE;
}
User::create([
'name' => explode('@', $email)[0],
'email' => $email,
'password' => $password,
]);
$this->info("Admin user created for {$email}.");
return self::SUCCESS;
}
}