choice('Subcommand', ['list', 'create', 'revoke', 'exit']); switch ($option) { case 'list': $this->listTokens(); break; case 'create': $this->createToken(); break; case 'revoke': $this->revokeToken(); break; case 'exit': break 2; } } return 0; } private function listTokens() { $tokens = AuthToken::all(['name']); if (sizeof($tokens) == 0) { $this->info("No tokens found"); } else { $this->table(["Token Name"], $tokens); } } private function createToken() { $tokens = AuthToken::all(); $name = $this->ask('name'); if ($tokens->where('name', $name)->first() !== null) { $this->error('There\'s already a token by that name'); return; } $tokenString = Str::random(config('chaosapi.token-length', 60)); AuthToken::create([ 'name' => $name, 'token' => $tokenString ]); $this->info('Token created, copy this as you won\'t be able to see it again.'); $this->info($tokenString); } private function revokeToken() { $tokens = AuthToken::all(); $name = $this->anticipate('Name?', $tokens->pluck('name')->toArray()); $token = $tokens->where('name', $name)->first(); if ($token === null) { $this->warn('There\'s no token authorized by that name'); } else { $this->info('Token \''.$name.'\' revoked'); $token->delete(); } } }