Laravel Artisan command for creating user with name, email and password
Just put the CreateUser.php
at app/Console/Commands/CreateUser.php
.
Then you'll get a command app:create-user
to run with artisan.
Run the following command from Laravel project directory.
php artisan app:create-user {username} {[email protected]} {mypassword}
The password will be autimatically encrypted and the user will be created.
Simple, isn't it? 😎
- There is a
--unverified
option. If you use it, the created user will remain unverified. Otherwise the user be created a email verified by default. - You should put the
CreateUserTest.php
attests/Feature/Console/CreateUserTest.php
. - The command with not allow duplicate Username and email address (see validations).
Create User (Tests\Feature\Console\CreateUser)
✔ User creates with valid args
✔ Cannot create user with invalid email
✔ Cannot create user with duplicate name
✔ Cannot create user with duplicate email
✔ Created users are verified by default
✔ Created users can be kept unverified
OK (6 tests, 19 assertions)