Created
March 17, 2021 12:43
-
-
Save wallacemaxters/b537af910834faddf3cf92c82fd728a5 to your computer and use it in GitHub Desktop.
Comando para criar o usuário interativamente através da linha de comando do artisan. Command to create user from php artisan interactively.
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
<?php | |
Artisan::command('make:user', function () { | |
$email = $this->ask('Digite um e-mail'); | |
$name = $this->ask('Digite o nome'); | |
$password = $this->secret('Digite a senha'); | |
$user = App\User::firstOrNew(['email' => $email]); | |
$exists = $user->exists; | |
$user->fill([ | |
'name' => $name, | |
'password' => bcrypt($password), | |
'api_token' => str_random(80), | |
])->save(); | |
$this->info( | |
sprintf('Usuário %s com sucesso!', $exists ? 'atualizado' : 'criado') | |
); | |
})->describe('Cria um usuário pela linha de comando'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mais detalhes em:
https://wallacemaxters.com.br/blog/2020/04/28/como-criar-um-usu%C3%A1rio-atrav%C3%A9s-do-artisan