'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); } }