Skip to content
Snippets Groups Projects
Unverified Commit fe409e2b authored by Robb Lewis's avatar Robb Lewis
Browse files

Better warnings, remove name - we don't need it

parent 9d58aae1
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -5,6 +5,7 @@ namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
 
Loading
Loading
@@ -43,6 +44,11 @@ class Setup extends Command
{
$this->setupDatabase();
 
if (User::first()) {
$this->warn('User account already created, aborting.');
return;
}
if (! $user = $this->createUser()) {
$this->info('Error: User creation failed. Please try again');
return;
Loading
Loading
@@ -53,20 +59,34 @@ class Setup extends Command
 
private function setupDatabase()
{
Artisan::call('migrate:install');
Artisan::call('migrate', ['--force' => true]);
if (Schema::hasTable('migrations'))
{
$this->warn('`migrate:install` already run, skipping');
} else {
$this->info('Running migration install');
Artisan::call('migrate:install');
}
if (Schema::hasTable('tweets'))
{
$this->warn('`migrate` already run, skipping');
} else {
$this->info('Running table migrations');
Artisan::call('migrate', ['--force' => true]);
}
}
 
private function createUser()
{
$name = $this->ask('Name');
$this->info('Creating user account');
$email = $this->ask('Email Address');
 
try
{
Validator::make(['email' => $email], ['email' => 'email'])->validate();
} catch (ValidationException $e) {
$this->info('Error: Invalid email. Aborting...');
$this->info('Error: Invalid email. aborting.');
return false;
}
 
Loading
Loading
@@ -75,12 +95,11 @@ class Setup extends Command
 
if ($password != $confirmPassword)
{
$this->info('Error: Passwords do not match. Aborting...');
$this->info('Error: Passwords do not match. aborting.');
return false;
}
 
return User::create([
'name' => $name,
'email' => $email,
'password' => $password
]);
Loading
Loading
Loading
Loading
@@ -15,7 +15,6 @@ class CreateUsersTable extends Migration
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment