Skip to content

Instantly share code, notes, and snippets.

@wallacemaxters
Created March 17, 2021 12:43
Show Gist options
  • Save wallacemaxters/b537af910834faddf3cf92c82fd728a5 to your computer and use it in GitHub Desktop.
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.
<?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');
@wallacemaxters
Copy link
Author

wallacemaxters commented Mar 17, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment