2017-12-14 21:05:26 -06:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-12-14 21:05:26 -06:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\WithoutTimestamps;
|
|
|
|
|
|
2022-12-12 15:47:48 -07:00
|
|
|
/**
|
|
|
|
|
* Pterodactyl\Models\Setting.
|
|
|
|
|
*
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property string $key
|
|
|
|
|
* @property string $value
|
|
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Fillable(['key', 'value'])]
|
|
|
|
|
#[WithoutTimestamps]
|
2020-04-03 23:22:35 -07:00
|
|
|
class Setting extends Model
|
2017-12-14 21:05:26 -06:00
|
|
|
{
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Store a persistent setting, replacing any value already stored for the key.
|
2017-12-14 21:05:26 -06:00
|
|
|
*/
|
2026-10-05 18:10:18 -04:00
|
|
|
public static function put(string $key, ?string $value): void
|
|
|
|
|
{
|
|
|
|
|
static::query()->updateOrCreate(['key' => $key], ['value' => $value ?? '']);
|
|
|
|
|
}
|
2017-12-14 21:05:26 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* Retrieve a persistent setting, or null when nothing is stored for the key.
|
|
|
|
|
*/
|
|
|
|
|
public static function fetch(string $key): ?string
|
|
|
|
|
{
|
|
|
|
|
return static::query()->where('key', $key)->first()?->value;
|
|
|
|
|
}
|
2017-12-14 21:05:26 -06:00
|
|
|
}
|