Initial commit
This commit is contained in:
44
api/app/Console/Commands/MakeAdminUser.php
Normal file
44
api/app/Console/Commands/MakeAdminUser.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user