34 lines
688 B
PHP
34 lines
688 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class SystemSetting extends Model
|
|
{
|
|
protected $fillable = [
|
|
'key',
|
|
'value',
|
|
];
|
|
|
|
/**
|
|
* Get a setting value by key with optional default fallback.
|
|
*/
|
|
public static function get(string $key, $default = null)
|
|
{
|
|
$setting = static::where('key', $key)->first();
|
|
return $setting ? $setting->value : $default;
|
|
}
|
|
|
|
/**
|
|
* Set or update a setting by key.
|
|
*/
|
|
public static function set(string $key, $value): self
|
|
{
|
|
return static::updateOrCreate(
|
|
['key' => $key],
|
|
['value' => (string) $value]
|
|
);
|
|
}
|
|
}
|