. */ namespace App\Console\Commands\Accounts; use Illuminate\Console\Command; use Carbon\Carbon; use App\Account; use App\ApiKey; class CreateAdminTest extends Command { protected $signature = 'accounts:create-admin-test'; protected $description = 'Create a test admin account, only for tests purpose'; public function __construct() { parent::__construct(); } public function handle() { $username = 'admin_test'; $domain = 'sip.example.org'; $this->call('spaces:create-update', [ 'domain' => $domain, '--super' => 'true' ]); $this->call('accounts:create-admin-account', [ '--username' => $username, '--domain' => $domain, '--password' => 'admin_test_password' ]); $secret = 'no_secret_at_all'; $account = Account::withoutGlobalScopes() ->where('username', $username) ->where('domain', $domain) ->first(); ApiKey::where('account_id', $account->id)->delete(); $apiKey = new ApiKey; $apiKey->account_id = $account->id; $apiKey->last_used_at = Carbon::now(); $apiKey->key = $secret; $apiKey->save(); $this->info('API Key updated to: ' . $secret); return Command::SUCCESS; } }