ask('What is the name?'); $email = $this->ask('What is the email?'); $pwd = $this->secret('What is the password?'); $user = new User(); $user->name = $name; $user->email = $email; if ($this->confirm('Is the user an admin?')) { $user->role = Role::admin(); } else { $user->role = Role::client(); try { $project = Project::where( 'id', $this->ask("What's the id of the project (s)he's working on?") )->firstOrFail(); $user->projects()->sync([$project->id]); } catch (ModelNotFoundException $e) { $this->error('The project does not exists'); return -1; } } $user->password = Hash::make($pwd); $user->save(); $this->info('User created.'); return 0; } }