45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Actions\Users\UpdateUserAvatar;
|
|
use App\Enums\Permission;
|
|
use App\Models\User;
|
|
use Illuminate\Console\Attributes\Description;
|
|
use Illuminate\Console\Attributes\Signature;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
#[Signature('app:create-admin-user {name=Admin} {email=admin@kanbangit.test} {password=test}')]
|
|
#[Description('Command description')]
|
|
class CreateAdminUser extends Command
|
|
{
|
|
public function __construct(
|
|
private readonly UpdateUserAvatar $avatars,
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): int
|
|
{
|
|
$user = User::create([
|
|
'name' => $this->argument('name'),
|
|
'email' => $this->argument('email'),
|
|
'password' => Hash::make($this->argument('password')),
|
|
]);
|
|
|
|
$this->avatars->generate($user);
|
|
|
|
$user->permissionAssignments()->create([
|
|
'permission' => Permission::GlobalAdmin,
|
|
]);
|
|
|
|
$this->info(sprintf('Admin User created with emil=\'%s\' and password=\'%s\'', $this->argument('email'), $this->argument('password')));
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|