PhyrePanel-mirror/web/tests/Feature/Api/ApiKeysTrait.php
2024-04-22 14:14:05 +03:00

28 lines
564 B
PHP

<?php
namespace Tests\Feature\Api;
use App\Models\ApiKey;
trait ApiKeysTrait
{
public function getApiKey()
{
$findApiKey = ApiKey::where('name', 'Unit Test API')->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();
}
}