55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\SettingGroup;
|
|
use App\Enums\SettingType;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Setting extends Model
|
|
{
|
|
/**
|
|
* Keys that should never appear in public API responses.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
public const SENSITIVE_KEY_PATTERNS = ['_key', '_secret', '_password'];
|
|
|
|
/**
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'group',
|
|
'key',
|
|
'value',
|
|
'type',
|
|
'label',
|
|
'order_index',
|
|
'is_public',
|
|
];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'group' => SettingGroup::class,
|
|
'type' => SettingType::class,
|
|
'is_public' => 'boolean',
|
|
'order_index' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function isSensitive(): bool
|
|
{
|
|
foreach (self::SENSITIVE_KEY_PATTERNS as $pattern) {
|
|
if (str_contains($this->key, $pattern)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|