Skip to content

Instantly share code, notes, and snippets.

@gnovaro
Forked from meigwilym/console.php
Created March 22, 2021 09:34
Show Gist options
  • Save gnovaro/6d787405ccae9ef2bc0ffae949baad41 to your computer and use it in GitHub Desktop.
Save gnovaro/6d787405ccae9ef2bc0ffae949baad41 to your computer and use it in GitHub Desktop.
Laravel Create User Command
<?php
// routes/console.php
// quickly create an user via the command line
Artisan::command('user:create', function () {
$name = $this->ask('Name?');
$email = $this->ask('Email?');
$pwd = $this->ask('Password?');
// $pwd = $this->secret('Password?'); // or use secret() to hide the password being inputted
\DB::table('users')->insert([
'name' => $name,
'email' => $email,
'password' => bcrypt($pwd),
'created_at' => date_create()->format('Y-m-d H:i:s'),
'updated_at' => date_create()->format('Y-m-d H:i:s'),
]);
$this->info('Account created for '.$name);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment