forked from nishangupta/Mart
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use App\Models\User; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class UserCreate extends Command | ||
{ | ||
use WithFaker; | ||
|
||
protected $signature = 'app:user:create | ||
{--name=} | ||
{--email=} | ||
{--password=} | ||
{--role=user} | ||
'; | ||
|
||
protected $description = 'Create User'; | ||
|
||
public function handle(): int | ||
{ | ||
$faker = $this->makeFaker(); | ||
|
||
/** @var User $newUser */ | ||
$newUser = User::factory()->create([ | ||
'name' => $this->option('name') ?? $faker->name, | ||
'email' => $this->option('email') ?? $faker->email, | ||
'password' => Hash::make($this->option('password') ?? 'password'), | ||
]); | ||
|
||
$newUser->assignRole($this->option('role')); | ||
|
||
$this->line('User created: '); | ||
$this->line($newUser->toJson()); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,32 +9,25 @@ class UserSeeder extends Seeder | |
{ | ||
public function run(): void | ||
{ | ||
// `password` | ||
$password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; | ||
|
||
$factoryUsers = [ | ||
[ | ||
'name' => 'Admin', | ||
'email' => '[email protected]', | ||
'password' => $password, | ||
'role' => 'admin' | ||
], | ||
[ | ||
'name' => 'Miles', | ||
'email' => '[email protected]', | ||
'password' => $password, | ||
'role' => 'shipper' | ||
], | ||
[ | ||
'name' => 'Nathan', | ||
'email' => '[email protected]', | ||
'password' => $password, | ||
'role' => 'user' | ||
], | ||
[ | ||
'name' => 'Ban', | ||
'email' => '[email protected]', | ||
'password' => $password, | ||
'role' => 'user' | ||
], | ||
]; | ||
|