54 lines
1.0 KiB
PHP
Executable File
54 lines
1.0 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\ChatGPT\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ChatGptApiSetting extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'chatgpt_api_settings';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'api_key',
|
|
'is_active',
|
|
];
|
|
|
|
protected $casts = [
|
|
'api_key' => 'encrypted',
|
|
'is_active' => 'boolean',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'api_key',
|
|
];
|
|
|
|
/**
|
|
* Get the currently active OpenAI API setting.
|
|
*/
|
|
public static function active(): ?self
|
|
{
|
|
return self::query()
|
|
->where('is_active', true)
|
|
->latest('id')
|
|
->first();
|
|
}
|
|
|
|
/**
|
|
* Return a masked version of the stored API key for display.
|
|
*/
|
|
public function maskedApiKey(): string
|
|
{
|
|
$key = (string) $this->api_key;
|
|
|
|
if ($key === '') {
|
|
return 'Not set';
|
|
}
|
|
|
|
return substr($key, 0, 7) . '...' . substr($key, -4);
|
|
}
|
|
}
|