first(); if ($findApiKey) { return $findApiKey; } $this->createApiKey(); return $this->getApiKey(); } public function createApiKey() { $apiKey = new ApiKey(); $apiKey->name = 'Unit Test API'; $apiKey->is_active = true; $apiKey->enable_whitelisted_ips = false; $apiKey->save(); } }