create user comand update

This commit is contained in:
Jérémy Munsch 2024-03-29 12:31:53 +01:00
parent 434de3adc5
commit 086fd74fe0
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC
2 changed files with 47 additions and 48 deletions

View file

@ -1,48 +0,0 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
use App\Models\User;
class AdminCreate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'admin:create';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create Admin User';
/**
* Execute the console command.
*
* @return integer
*/
public function handle()
{
$role = 0;
$name = $this->ask('Name ?');
$email = $this->ask('Email ?');
$password = $this->secret('What is the password?');
$user = new User([
'name' => $name,
'email' => $email,
'role' => $role,
'password' => Hash::make($password)
]);
$user->saveOrFail();
$this->info('Admin created.');
return 0;
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class UserCreate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:create';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a backend user';
/**
* Execute the console command.
*
* @return integer
*/
public function handle()
{
$name = $this->ask('What is the name?');
$email = $this->ask('What is the email?');
$role = $this->ask('What is the role 1 (SuperAdmin) or 2 (Admin) ?') == '1' ? 1 : 2;
$pwd = $this->secret('What is the password?');
$user = new User();
$user->name = $name;
$user->email = $email;
$user->role = $role;
$user->password = Hash::make($pwd);
$user->saveOrFail();
$this->info('User created.');
return 0;
}
}